Angularjs Examples

AJS Examples


AngularJS ng-Change Directive

The ng-change directive is used to execute the expression when input changed.

Syntax

<p ng-change="yourFunction()"></p> 

AngularJS ng-Change Directive Example

<html>
<head>
<title>My first AngularJS ng-change Directive code</title>
<Script SRC="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js">
</Script>
<Script>
//Defining Controller Using Standard Javascrip Object Constructor
function CustomerController($scope) {
$scope.presentValue = '';
$scope.changed = function() {
        $scope.changedValue = $scope.presentValue + ' Value Changed';
      };
  
}
</Script>
</head>
<body>
<div ng-app="">
<div ng-controller="CustomerController"> 

<input type="text" ng-model="presentValue" ng-change="changed()" id="ng-change1" /></br>
Display : {{ changedValue }}

</div>
</div>
</body>
</html>
See Live Example