English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js">/script> </head> <body ng-app="myApp"> <div ng-controller="myCtrl"> <p>Enter some information in the input box:</p>/p> <input type="text" ng-change="myFunc()" ng-model="myValue" /> <p>The input box has been modified <span>{{count}}</span> times.</p>/p> </div> <script> angular.module('myApp', []) .controller('myCtrl', ['$scope', function($scope) { $scope.count = 0; $scope.myFunc = function() { $scope.count++; }); }); </script> </body> </html>Test to see ‹/›
ng-change Directives are used to tell AngularJS what operations need to be performed when the value of an HTML element changes.
ng-change Directives need to be paired with ng-model
Usage of Directives
AngularJS ng-change Directives do not override the native onchange event, If this event is triggered,ng-change Both the expression and the native onchange event will be executed.
ng-change The event triggers with each change of the value, it does not need to wait for a complete modification process, or wait for the focus to be lost.
ng-change The event only targets the real modification of the input box value, not the modification through JavaScript.
<element ng-change="expression"></element>
Supports <input>, <select>, and <textarea> elements.
Value | Description |
---|---|
expression | Execute expressions when the element value changes. |