1. How directives are compiled:
HTML compilation happens in three phases:
$compile
traverses the DOM and matches directives.If the compiler finds that an element matches a directive, then the directive is added to the list of directives that match the DOM element. A single element may match multiple directives.- Once all directives matching a DOM element have been identified, the compiler sorts the directives by their
priority
.Each directive'scompile
functions are executed. Eachcompile
function has a chance to modify the DOM. Eachcompile
function returns alink
function. These functions are composed into a "combined" link function, which invokes each directive's returnedlink
function.
2. Difference between Controller and Link
When do I want my code to run
- Before compilation? – Controller
- After compilation? – Link
3. Controller "$scope" and link "scope"
- controller ‘$scope’ and link ‘scope’ are the same thing. The difference is paramaters sent to the controller get there through Dependency Injection (so calling it ‘$scope’ is required), where parameters sent to link are standard order based funcitons.
4. Why do we have "controller" in directive
So we can do awesome stuff like using one directives controller in another. We simply set something we want to “this” and get it using the “require” option in the directive.
Reference Link:
http://jasonmore.net/angular-js-directives-difference-controller-link/
https://docs.angularjs.org/guide/compiler
https://docs.angularjs.org/guide/compiler
No comments:
Post a Comment