Reputation:
So I load my page, which contains a single directive.
<my-directive></my-directive>
I know that Angular will run the compile, then controller, then the link function for myDirective. When does Angular set up the $watches?
I guess that it would be set up during the controller, but then does that mean the $digest cycle completes before the link function?
Upvotes: 4
Views: 38
Reputation: 52847
You can setup $watchers anywhere you have access to scope. That includes ngController constructors, directive controllers, and link functions. However the proper place to do it is in the link function of a directive definition.
$watchers execute during the digest cycle which occurs after the linking phase (I.e. After all the directives have been linked)
Upvotes: 2