Order of execution of directive functions in AngularJS

前端 未结 2 863
盖世英雄少女心
盖世英雄少女心 2020-12-09 10:28

What is the order of execution of directive functions? The documentation doesn\'t seem to address this.

Ex

  1. template / templateUrl (is evaluated)
2条回答
  •  执笔经年
    2020-12-09 10:59

    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().

提交回复
热议问题