Mastering Web Application

(Rick Simeone) #1
Chapter 9

Injecting dependencies

First, as we saw previously, directive controllers must use dependency injection
annotations to specify what services it needs, for example, $scope, $element,
and $attrs. A link function is always passed the same four parameters: scope,
element, attrs, and controller, regardless of the names of these parameters in
the function definition.


The compilation process

Directive controllers and link functions are called at different times during the
compilation process. Given a set of directives on DOM elements with this structure:


parent
..child 1
....child 1 a

....child 1 b

The directive controllers and link functions are invoked in this order:



  • parent (controller)

  • parent (pre-link)
    ° child 1 (controller)
    ° child 1 (pre-link)


° child 1 a (controller)
° child 1 a (pre-link)
° child 1 a (post-link)
° child 1 b (controller)
° child 1 b (pre-link)
° child 1 b (post-link)
° child 1 (post-link)


  • parent (post-link)

Free download pdf