Reputation: 4993
http://jsbin.com/secuz/5/edit?html,js,output
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?
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?
Tried 2 additional scenarios:
ng-if
s, then the propagation happens from outside-in, just as expected:[[ '1 if', true ], [ '2 if', true ], [ '1 if', true ], [ '2 if', true ]]
ng-show
s exhibit a counter-intuitive behaviour:[[ '2 show', true ], [ '1 show', true ], [ '2 show', true ], [ '1 show', true ]]
Upvotes: 2
Views: 118
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