This document summarizes AngularJS scopes, digest cycles, data binding, dependency injection, and modularity. It discusses how scopes are created and inherited, how to use $digest and $watch, how expressions are evaluated, the benefits of dependency injection, and best practices for managing modules. Key recommendations include trusting the scope hierarchy, using $apply instead of $digest, avoiding non-isolated directives, and structuring code into independent, testable modules.
10. Do not use $digest, use $apply in directives.
$digest is a single run, not the full cycle
11. $watch expression is called in $scope’s context!
In the expression this will refer to the $scope!
Do not use $watch with property getters without binding.
12. $digest event propagates inside isolated scopes!
The change in parent scope will trigger isolated watchers
13. Use events to handle ‘model changes’ sparingly [4]
Use $watch instead.
Digest cycle is fast…
…until you write bloated $watch exressions.
Watchtower [5] comes to the rescue!
18. Expressions can have function call reference
You can specify parameters to be passed upon the call.
“someMethodCall( param1, param2 )”
Not very common, is it?
It should be called like this in JS:
someMethodCall( { param1 : ‘value’,
param2: ‘value2’
})
23. AngularJS ‘runtime’ is an IoC container.
Read it like this: you should wrap 3rd party components, which are not
integrated with angular, into directives/services.
You can’t inject (use) them as is!
27. Using Angular with module loaders can be tricky
Angular ‘modules’ has a different nature.
Need some handcrafting to make modules and ‘modules’ play nicely.
28. Keep services/directives/modules as independent as possible.
This is #1 priority.
Use isolated scope for main directives.
Keep shared state in services.
Keep constructors in factories.
29.
30. [1] In scope we trust
[2] 1 scope per 1 element
[3] Run, $digest, run!
[4] Why dirty checkings and not events?
[5] Project 'Watchtower'
[6] My name is Bind, Data Bind!
[7] Injections are the best things...
[8] Minification problem in Angular
[9] ngmin
[10] True independence and freedom
can only exist in doing what's right.
[11] module-per-feature architecture
Links
@mr_mig_by Alexey Migutsky