Creado por James Drummond
hace casi 10 años
|
||
See: http://www.sitepoint.com/practical-guide-angularjs-directives/
See also: http://stackoverflow.com/questions/12164138/what-is-the-difference-between-compile-and-link-function...Compile function: Use for *template* (as opposed to instance) manipulation. Changes apply to all DOM clones of the template associated with the directive. - The compile function does *not* receive a scope argument.*** Important ***The compile function receives the attributes of the directive element as an argument. So a good use case for using compile would be adding a class to the element which is registered on the directive as an attributeLink function: Use for registering DOM listeners (i.e. $watch listeners on the instance scope) as well as instance DOM manipulation. - It is executed *after* the template has been cloned
See: http://stackoverflow.com/questions/12164138/what-is-the-difference-between-compile-and-link-function...Be sure that you understand the difference between:The Compiler Service - Angular service that traverses the DOM looking for attributes.And the compilation process which happens in two phases: - Compile. Traverse the DOM looking for all the directives. The result is a linking function. - Link. 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 the single source of truth.If you are going to make DOM transformations, it should be compile. If you want to add some features that are behavior changes, it should be in link.
See: http://stackoverflow.com/questions/24615103/angular-directives-when-and-how-to-use-compile-controlle... ** This is a very good link **Also: http://www.jvandemo.com/the-nitty-gritty-of-compile-and-link-functions-inside-angularjs-directives/ ** This is very good as well **
How does Angular process directives? 1. When the DOM is ready, Angular starts to process the page, looking for the ng-app directive. At that point, Angular begins to recursively parse the page, looking for other directives. 2. Angular compiles all directives before linking them to their scope.
¿Quieres crear tus propios Apuntes gratis con GoConqr? Más información.