ng-change

Description

ng-change directive evaluates the given expression when the input changes.

Example

The following code shows how to ng-change.


<!-- w  w  w. j  ava2s  .co  m-->

<!doctype html>
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>
  <div ng-controller="MyController">
    <p>type any number into the text field</p>
    <input type="text" ng-model="equation.x" ng-change="change()" />
    <code>{{ equation.output }}</code>
  </div>
  <script>
    angular.module('myApp', [])
    .controller('MyController', function($scope) {
      $scope.equation = {};
      $scope.change = function() {
           $scope.equation.output = Number($scope.equation.x) +" is the new value";
      };
    });
  </script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Tutorial »




Introduction
Buildin Filters
Buildin Directives