English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Detailed Explanation of AngularJS Execution Process

First: Startup phase

When the browser parses the HTML page, after reading the <script> tag of angular.js, it will stop parsing the following DOM nodes and start executing angular.js. At the same time, Angular will set an event listener to listen to the DOMContentLoaded event. When Angular detects this event, Angular starts.

Second: Initialization phase

After Angular starts, it will look for ng-Command app instructions, then initialize a series of necessary components (i.e., $injector, $compile service, and $rootScope), and then continue to parse the DOM.

3. Compilation and Linking Phase

1. Angular uses the $compile service to find DOM elements with directives by traversing the DOM tree, and then sorts the found directives according to the priority of the directives.

2. Then, use the $injector service to find and collect the compile function under each directive and execute it.

3. After the compile method of each node is executed, the $compile service calls the link function. This link function sets up monitoring for directives bound to the enclosed scope. This action creates a live view.

4. After all the above is completed, Angular is fully started

4. Running Phase

Angular provides its own event loop. Directives will register event listeners themselves, so when an event is triggered, the directive function will run in the AngularJS $digest loop. The $digest loop will wait for the $watch expression list, and when a model change is detected, it will call the $watch function, and then check the $watch list again to ensure that no model has changed. Once the $digest loop stabilizes and no potential changes are detected, the execution process will leave the Angular context and usually return to the browser.

That's all for this article. I hope the content of this article can bring you some help in learning or working, and I also hope to get more support for the Niyao tutorial!

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please report any violations by sending an email to codebox.com (replace # with @ when sending an email), and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.

You May Also Like