Ng-Change-3

 

In this example we have a textbox and when you type in the textbox the value changes and on the change of the value we increment the value of count variable by 1 by calling function on the change event using the ng-change directive. The value of count variable is display below the textbox.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="changeExample"> <div ng-controller="ExampleController"> <div class="container"> <div class="col-md-3 well" ng-init="count=0"> First Name: <input type="text" class="form-control" ng-change="isTextChange()" ng-model="text" /> <pre><b>Changed</b> {{isChange}} {{count}} </pre> </div> </div> </div> <script> var app = angular.module("changeExample", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.isChange = false; $scope.isTextChange = function () { $scope.isChange = true; $scope.count = $scope.count + 1; } }]); </script> </body> </html>
Output