Wizek
Wizek

Reputation: 4993

AngularJS : How to make directives evaluate from outside in?

Executable example:

http://jsbin.com/secuz/5/edit?html,js,output

Details

The above failure contradicts my assumption about in what order Angular directives are processed. I would expect that outer directives get run first, then execution propagates inwards.

Am I correct to think that this out-of order evaluation is due to ng-if having higher priority than ng-show? And if so, shouldn't priorities only be taken into account if two directives are on the same element?

Main question

How can I make sure execution always goes from outside in? Do I need to give the same priority to all the directives I use?

Edit:

Tried 2 additional scenarios:

[[ '1 if', true ], [ '2 if', true ], [ '1 if', true ], [ '2 if', true ]]

[[ '2 show', true ], [ '1 show', true ], [ '2 show', true ], [ '1 show', true ]]

Upvotes: 2

Views: 118

Answers (1)

SimplGy
SimplGy

Reputation: 20437

Compilation involves these three call-back-bindable steps:

  • compile
  • pre-link
  • post-link

More here.

I am not sure where ng-show and ng-if do their behavior, but I bet you could find out.

If ng-show and ng-if set up the behavior you're testing in the post-link, that actually executes in reverse order, climbing up from the lowest element and back out, so this would explain your finding.

Upvotes: 2

Related Questions