http://eng.localytics.com/tips-and-tricks-for-debugging-unfamiliar-angularjs-code/
Created
July 8, 2016 08:54
-
-
Save JohnnyMa/a4743bf9065018d7caf42aed49d620aa to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
angular
生命周期:
创建
链接
更新
销毁
设置作用域的初始状态,添加自定义行为
Dependency Annotation:
use strict:
ng-strict-di, 设置了该属性以后,在使用“Implicit Annotation”的方式来DI的话会抛出一条error。
- Event
Different service types in Angular
provider
factory
value
service
constant
angular.module("testModule", [])
.factory("testgreeting", function() {
})
.service("testgreeting", function() {
})
.provider("testgreeting", function() {
})
.value("testgreeting", function() {
})
.constant("testgreeting", function() {
})
Scope $watch Performance
有3种方式:
- scope.$watchCollection (watchExpression, listener)
TODO:
scope.$apply(customFn)
Here is the explanation of how the Hello world example achieves the data-binding effect when the user enters text into the text field.
During the compilation phase:
the ng-model and input directive set up a keydown listener on the control.
the interpolation sets up a $watch to be notified of name changes.
During the runtime phase:
Pressing an 'X' key causes the browser to emit a keydown event on the input control.
The input directive captures the change to the input's value and calls $apply("name = 'X';") to update the application model inside the Angular execution context.
Angular applies the name = 'X'; to the model.
The $digest loop begins
The $watch list detects a change on the name property and notifies the interpolation, which in turn updates the DOM.
Angular exits the execution context, which in turn exits the keydown event and with it the JavaScript execution context.
The browser re-renders the view with the updated text.
tips & tricks
I strongly recommend learning the different types of angular services. They are a significant source of confusion when trying to wrap your head around an AngularJS code base.
refer links:
http://angular-tips.com/blog/2013/08/understanding-service-types/
http://eng.localytics.com/tips-and-tricks-for-debugging-unfamiliar-angularjs-code/