Latest web development tutorials

AngularJS ng-change instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS examples

When the value of the function is executed to change the input box:

<Body ng-app = "myApp ">

<Div ng-controller = "myCtrl ">
<Input type = "text" ng -change = "myFunc ()" ng-model = "myValue" />
<P> The input field has changed {{count}} times. </ P>
</ Div>

<Script>
angular.module ( 'myApp', [] )
.controller ( 'myCtrl', [ ' $ scope', function ($ scope) {
$ scope.count = 0;
$ scope.myFunc = function () {
$ Scope.count ++;
};
}]);
</ Script>

</ Body>

try it"

Definition and Usage

ng-change instruction is used to tell the operator AngularJS HTML element value changes when you need to perform.

ng-change instruction need to match ng-model instruction.

AngularJS ng-change instruction command does not overwrite native onchange event, if the event is triggered,ng-change expression with native onchange event will be executed.

ng-change events at each change of value triggers, it does not need to wait for a completion of the modification process, or wait for the action loses focus.

ng-change event only for real input box value to modify, rather than modified by JavaScript.


grammar

<Element ng-change = "expression "> </ element>

<Input>, <select>, and <textarea> element supports.


Parameter Value

value description
expression When executing the expression element values ​​change.

AngularJS Reference Manual AngularJS Reference Manual