Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular directive execution order

If I have a number of directives applied to an element in AngularJS, in what order will they be executed?

For example:

<input ng-change='foo()' data-number-formatter></input>

Will the number formatter or the change event be fired first. Is it deterministic?

like image 354
Ben Aston Avatar asked Feb 11 '23 00:02

Ben Aston


1 Answers

The order in which directives are compiled is directly based on their priority:

From the docs:

When there are multiple directives defined on a single DOM element, sometimes it is necessary to specify the order in which the directives are applied. The priority is used to sort the directives before their compile functions get called. Priority is defined as a number. Directives with greater numerical priority are compiled first. Pre-link functions are also run in priority order, but post-link functions are run in reverse order. The order of directives with the same priority is undefined. The default priority is 0.

like image 90
CodingIntrigue Avatar answered Feb 12 '23 13:02

CodingIntrigue