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?
-
3The answer to your question is already here .. stackoverflow.com/questions/9682092/databinding-in-angularjsGanaraj– Ganaraj2013-05-17 09:25:35 +00:00Commented May 17, 2013 at 9:25
Add a comment
|
1 Answer
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.)
1 Comment
aztack
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 ?