Order of execution of directive functions in AngularJS

angularjs, angularjs-directive, javascript

Solution

Pre-linking function: Executed before the child elements are linked. Not safe to do DOM transformation since the compiler linking function will fail to locate the correct elements for linking.

Post-linking function: Executed after the child elements are linked. It is safe to do DOM transformation in the post-linking function.

Above excerpt is taken from the official docs on directives.

So, to answer your question, Post-linking/Link function is when/where you can safely operate on element.children().

Problem

What is the order of execution of directive functions? The documentation doesn't seem to address this. Ex - template / templateUrl (is evaluated) - controllerFn - compileFn - linkFn Answer From answer below: http://plnkr.co/edit/79iyKSbfxgkzk2Pivuak (plunker shows nested and sibling directives) - Template is parsed - `compile()` (changes made to the template within compile are proliferated down to linking functions) - `controller()` - `preLink()` - `postLink()`

Original source