Tutorialsplane

angular.bind


angular.bind function – It basically returns a function(fn) which is bound to itself. You can also supply optional arguments that are prebound to the function.
Here is this tutorial we are going to explain how to use the angular.bind function with example and online demo.


angular.bind Function Example

Syntax

Syntax for the angular.bind is given below –

Syntax:

angular.bind(self, fn, args);

Arguments

Here is simple example of angular bind. In this example angular bind is used to bind the add function and the arguments – $scope.input1, $scope.input2 will be passed to the add function. The below example accepts two arguments and returns their addition –

angular.bind function example :




 
 

  
<div ng-app="myApp">  
<div ng-controller="myController"> 
 
 Enter a number 1.
 <br/>
 Enter a number 2
 
 <br/>number 1 + number 2 = {{result}}<br/>

</div> 
</div>
  
      

Try it »

If you run the above example it will produce output something like this –

AngularJs Api Refrence

AngularJs Directive