AngularJS ng-change example

AngularJS ng-change expression is evaluated when the user changes the input.

<div ng-app="myApp" ng-controller='MyCtrl'>
  <input type="text" ng-model="name" ng-change="inc()" ng-init="count=0;"><br>
  number of times input changed: {{count}}
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script>
var module = angular.module('myApp', []);
module.controller('MyCtrl', function($scope) {
  $scope.inc = function() {
    $scope.count++;
  }
});
</script>
refresh
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments