Thursday, August 7, 2014

Angular.js: Directive execution order

Last week, a colleague asked me if there is a way to control the order in which your Angular.js Directives get executed.

Of course you can! Every directive has a ‘priority’ property. When there are multiple directives defined on a single DOM, the priority is used to sort the directives before their compile functions get called. Directives with greater numerical priority are compiled first. The default priority is 0.

An example:

3 comments:

M3rken said...

Thanks, Bart.

Hadn't found that solution in the documentation.

Just for reference, here are some additional options for configuring directives : https://docs.angularjs.org/api/ng/service/$compile

optisol biz said...

Great post. I’ve learned a lot of info from your blog so far. kindly update the latest technology or frameworks. Thanks..

Ruby on Rails Developers

The Angular.JS said...

Hi,

Great. I has the doubt on how it works exactly. Now my double is cleared on the directive execution order.

Thanks

Angularjs Training in Chennai