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?
Asked
Active
Viewed 3,154 times
2

aztack
- 4,376
- 5
- 32
- 50
-
3The answer to your question is already here .. http://stackoverflow.com/questions/9682092/databinding-in-angularjs – ganaraj May 17 '13 at 09:25
1 Answers
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.)

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875
-
the example in `Runtime section` is easy to understand, since 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 ? – aztack May 17 '13 at 09:54