AngularJS ng-change Instruction
AngularJS Examples
Execute a function when the value of the input field changes:
<
body
ng-app=
"myApp"
<
div
ng-controller=
"myCtrl"
<
input
type=
"text"
ng-change=
"myFunc()"
ng-model=
"myValue"
/
<
pThe 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
<
/bodyTry it »
Definition and Usage
ng-change The directive tells AngularJS the action to take when the value of an HTML element changes.
ng-change The directive needs to be used together with ng-model directive.
AngularJS ng-change The directive does not override the native onchange event. If the event is triggered,ng-change both the expression and the native onchange event will be executed.
ng-change The event is triggered on every change of the value; it does not need to wait for a complete change process or for a loss of focus.
ng-change The event is only for real changes to the input field value, not changes made through JavaScript.
Syntax
<
element
ng-change=
"expression"
<
/element,
Parameter value
| Value | Description |
|---|---|
| expression | The expression to execute when the element value changes. |
AngularJS Reference Manual