在AngularJS的指令功能执行顺序 [英] Order of execution of directive functions in AngularJS
问题描述
什么是指令功能执行的顺序?该文档似乎并没有解决这个问题。
前
- 模板/ templateUrl(评估)
- controllerFn
- compileFn
- linkFn
答
通过回答如下:的 http://plnkr.co/edit/79iyKSbfxgkzk2Pivuak (plunker显示嵌套和兄弟指令)
- 模板被解析
-
编译()
(编译内模板所做的更改激增到连接功能) -
控制器()
-
$ P $砰砰()
-
postLink()
pre-链接功能:子元素链接之前执行。
没有安全做DOM转型,因为编译器链接功能
将无法找到正确的元素联系起来。
后链接功能:子元素被链接后执行。它
是安全的DOM转型后链接功能。
块引用>以上摘录从指令官方文档拍摄的。
因此,要回答你的问题,的张贴联/ Link功能的是,当/在那里你可以安全地运行element.children()。
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()
解决方案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().
这篇关于在AngularJS的指令功能执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!