Evaluate given expression when user changes the input. The expression is not evaluated when the value change is coming from the model.
Note, this directive requires ngModel
to be present.
<ng-change> </ng-change>
<script> function Controller($scope) { $scope.counter = 0; $scope.change = function() { $scope.counter++; }; } </script> <div ng-controller="Controller"> <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" /> <input type="checkbox" ng-model="confirmed" id="ng-change-example2" /> <label for="ng-change-example2">Confirmed</label><br /> debug = {{confirmed}}<br /> counter = {{counter}} </div>
it('should evaluate the expression if changing from view', function() { expect(binding('counter')).toEqual('0'); element('#ng-change-example1').click(); expect(binding('counter')).toEqual('1'); expect(binding('confirmed')).toEqual('true'); }); it('should not evaluate the expression if changing from model', function() { element('#ng-change-example2').click(); expect(binding('counter')).toEqual('0'); expect(binding('confirmed')).toEqual('true'); });