Anguar work process

Anguar's work process



Anguar's instruction compilation process:
1. First load the angularjs library, find the ng-app instruction, and find the boundaries of the application,
2. According to the scope delimited by ng-app, call the $compile service to compile, angularjs will Traverse the entire HTML document, and process each instruction declared on the
page Arrange according to the priority of the
instruction 3. Convert the DOM according to the configuration parameters (template, place, transclude, etc.) in the instruction and then Start to execute the compile function of each instruction in order (
if there is a compile function defined on the instruction) to convert the template itself
4. Note: The compile function here is configured in our instruction, which is different from the $compile service mentioned above. After each compile function is executed, a
link function will be returned, and all link functions will be combined into a large link function
5. Then this large link function will be executed, mainly for data binding, by registering listeners on the DOM To dynamically modify the data in the scope, or use
$watchs to monitor variables in the scope to modify the DOM, thereby establishing two-way binding, etc.
6. If the compile function is not configured in our command, the link function we configured will run, and what she does is roughly
the same as the large link function synthesized by all the link functions after the above complie returns.
7. Therefore: the compile and link options in the instruction are mutually exclusive. If these two options are set at the same time, the function returned by compile will be regarded as a link
function , and the link option itself will be ignored.


Reference to the original text: http://www.jb51.net/article/83051.htm

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327009764&siteId=291194637