Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://docs.angularjs.org/guide/compiler" rel="nofollow noreferrer">From the docs:</a></p> <blockquote> <h2>Compiler</h2> <p>Compiler is an angular service which traverses the DOM looking for attributes. The compilation process happens into two phases.</p> <ol> <li><p><strong>Compile:</strong> traverse the DOM and collect all of the directives. The result is a linking function.</p></li> <li><p><strong>Link:</strong> combine the directives with a scope and produce a live view. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model. Making the scope model a single source of truth.</p></li> </ol> <p>Some directives such <a href="http://docs.angularjs.org/api/ng.directive:ngRepeat" rel="nofollow noreferrer"><code>ng-repeat</code></a> clone DOM elements once for each item in collection. Having a compile and link phase improves performance since the cloned template only needs to be compiled once, and then linked once for each clone instance.</p> </blockquote> <p>So at least in some cases, <strong>the two phases exist separately as an optimization.</strong></p> <hr> <p><a href="https://stackoverflow.com/questions/12164138/what-is-the-difference-between-compile-and-link-function-in-angularjs/12164194#comment16280957_12164194">From @UmurKontacı</a>:</p> <blockquote> <p>If you are going to make DOM transformations, it should be <code>compile</code>. If you want to add some features that are behavior changes, it should be in <code>link</code>.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload