AngularJS ng-changeDirective
AngularJS Example
Execute a function when the value of an input field changes:
<div ng-controller="myCtrl">
<input type="text" ng-change="myFunc()" ng-model="myValue" />
<p>The input field has changed {{count}} times.</p>
</div>
<script>
.controller('myCtrl', ['$scope', function($scope) {
$scope.count = 0;
$scope.myFunc = function() {
$scope.count++;
};
}]);
</body>
Try it Yourself »
Definition and Usage
ng-changeThe ng-change directive tells AngularJS what to do when the value of an HTML element changes.
ng-changeThe ng-change directive needs to be used withng-modelthe ng-model directive.
AngularJS ng-changeThe ng-change directive does not override the native onchange event. If that event is triggered,ng-changeboth the expression and the native onchange event will be executed.
ng-changeThe event is triggered on every change of the value; it does not need to wait for a completed modification process or for the action of losing focus.
ng-changeThe event only targets actual changes to the input field's value, not modifications made via JavaScript.
Syntax
<input>, <select>, and <textarea> elements are supported.
Parameter Value
| Value | Description |
|---|---|
| expression | An expression to execute when the element's value changes. |
Other Extensions
AngularJS Reference Manual