1

As mentioned in w3schools doc:

The ng-change event is only triggered if there is a actual change in the input value, and not if the change was made from a JavaScript.

So, when I initialize ng-model by $scope in my controller, ng-change does not trigger.

Any idea?

1 Answer 1

2

change in model value from controller will not fire change event on DOM, its expected behaviour. In general event are placed on DOM not on value change.

ng-change event is an directive(declarative way) provided by angular for attaching change event on input/select element.

That means when you change in the input/select value then only that ng-change handler is going to fire

<input type="text" ng-change="changesHappen()" ng-model="testModel"/>
Sign up to request clarification or add additional context in comments.

2 Comments

Nice description, but I have two select box and the value of the second one is providing by the first one's ng-change function. In one case, the first one is coming from server and set to it's ng-model. In this case, second select show noting.
@vahidnajafi could you please create a fiddle/plunkr?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.