Angular $compiler

Source: Internet
Author: User

How directive was compiled

HTML compilation takes place in three phases:

1. $compile traverse DOM node matching directives

If compiler finds directive,directive on the element it is added to the directives list of matching DOM elements, an element can have more than one directives

2. All directives that are bound to the DOM element once determined, compiler will sort the directives by priority

Each directive's compile function is executed. Each compile function has a chance to change the DOM. Each compile function returns the link function. These functions call the link function returned by each directive to form a combined link function

3. $compile link scope and template by calling the composite link function described in the previous step. Call Directives's link function in turn, configure the Register element for each directive to listen for events, and set the scope's $watch listener

var$compile = ...;//injected into your codevarScope = ...;varParent = ...;//DOM element where the compiled template can be appendedvarhtml = ' <div ng-bind= ' exp ' ></div> ';//Step 1:parse HTML into DOM elementvarTemplate =angular.element (HTML);//Step 2:compile the templatevarLINKFN =$compile (template);//Step 3:link The compiled template with the scope.varelement =LINKFN (scope);//Step 4:append to DOM (optional)Parent.appendchild (Element);

Angular $compiler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.