Order of execution of directive functions in AngularJS

前端 未结 2 864
盖世英雄少女心
盖世英雄少女心 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 11:12

    on related note, here my understanding of exec order across the DOM.

    Here is a demo (open browser JS console)

    Given this DOM using directive foo:

      
    one
    one.one
    two

    ...AngularJS will traverse the DOM - twice - in depth-first order:

    1st pass foo.compile()

    1) compile: 1

    2) compile: 1_1

    3) compile: 2

    2nd pass: foo.controller() traversing down; foo.link() while backtracking

    controller: 1

    controller: 1_1

    link: 1_1

    link: 1

    controller: 2

    link: 2

提交回复
热议问题