2

For me,it's like magic. How dose Angular know watched expression has changed, and then call the callback? As far as I know, not all JavaScript implementation offer __defineSetter__ and __defineGetter__. Can someone explain how it works?

1

1 Answer 1

4

Angular works by keeping track of the old values of your model data properties, and checking the current values against them after various triggers. So it detects the changes by doing the comparisons. You can find the details in the Runtime section of this page. (I didn't link directly to the Runtime section because that page currently uses the Bootstrap navbar at the top, which has a bug where it hides the first couple of lines of content when you link to a fragment.)

Sign up to request clarification or add additional context in comments.

1 Comment

the example in Runtime section is easy to understand, since <input > triggers events, Angular can update data model and trigger callback. How about change model properties in $http.get callback?When does Angular get a chance to know your code changed model properties and then call $watch's callback? Does Angular check the changes after every $http.get, $http.post, etc ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.