Angular-bind-1

 

Angular.bind will bind to a function which call another function and arguments will also passed from addData, In this example, there are two value one is 5 and another is first time 30 and later it take value form text box which is bind to scope variable num. See the code snippet:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="bindController"> <input type="number" ng-model="num" ng-change="AddValue()" /> Addition={{Add}} </div> </body> </html> <script> var app = angular.module("app", []); app.controller('bindController', ['$scope', function ($scope) { $scope.num = 30; $scope.AddValue = function () { var addData = angular.bind(this, function (a, b) { return a + b; }); $scope.Add = addData(5, $scope.num); } }]); </script>
Output