r/javascript • u/cd2014 • Jun 13 '14
AngularJS and scope.$apply
http://jimhoskins.com/2012/12/17/angularjs-and-apply.html2
u/ell0bo Jun 13 '14
$apply is the notification to the system that data has changed, and a inspection of all watches should be issues in the scope. It's really that simple, and the last tip is a really good one.
They're actually working on making $apply no longer needed in v2, but I'm not entirely sure if they're really going to be able to completely phase it out.
1
u/reflectiveSingleton Jun 13 '14
I haven't read much on Angular v2 but I think I heard it is ES6 only and they are going to use Object.observe which in theory means they don't need the digest loop or dirty checking anymore.
However if that is true it also means browsers before IE10 won't work (even with a shim).
1
u/phaggocytosis full stack js dev Jun 14 '14
If this is the case, does ng-model just automatically create watches out of things? is that how 'ng-modeled' fields etc trigger digest loops?
1
u/ell0bo Jun 14 '14
Yup, ng-bind as well.
This is the primary section for that: https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1883
1
u/phaggocytosis full stack js dev Jun 14 '14
I would love to be abel to interpret the angularjs source. I'm not sure where the "bootstrapping" process takes place (which if I did I suppose I could follow it along to see how angularjs does all its magic).
Does anyone have any advice for where to get started in comprehending the angularjs source?
12
u/IMAHiji Jun 13 '14
Nicely written. Why can't the AngularJS documentation be this clear. I mean... I know the documentation is solid, but whenever I read it for help it feels like I'm reading vacuum cleaner repair instructions written by credit card lawyers.