ngSwitchWhen Priority Is Higher Than ngRepeat Priority In AngularJS 1.3
This is a really minor post about a change in directive priority in AngularJS 1.3. The other day, in my post about using multiple templates in a single ngRepeat directive, Boris Litvinsky brought it to my attention that ngSwitchWhen now executes at a higher priority (1,200) than the ngRepeat directive (1,000). While it wasn't necessarily relevant to my previous post, it does mean that as of AngularJS 1.3, the ngSwitchWhen directive can now be used to conditionally link ngRepeat directives.
Prior to AngularJS 1.3, the ngSwitchWhen directive used to execute at priority 800. This means that if you used it on the same element as ngRepeat (priority 1,000), it would transclude the element after ngRepeat had cloned it. It would then attempt to link the second clone in the context of ngSwitch, which is absolutely not what the developer was intending.
As of AngularJS 1.3, the ngSwitchWhen directive executes at priority 1,200 which means that it executes before ngRepeat. As such, the ngSwitchWhen directive can now work in conjunction with the ngSwitch directive to conditionally include an ngRepeat block:
Personally, I've never run into this limitation (and I'm still on AngularJS 1.0.8 in production). I've never needed to put ngSwitchWhen and ngRepeat on the same element. Typically, I would put ngSwitchWhen on a container and then have the ngRepeat as part of the descendant content. That said, I'm sure there are use-cases where this is a valuable change. And, it's good to see the AngularJS team continually refining and optimizing their directives.
Want to use code from this post? Check out the license.
Intresting, thanks Ben And Boris!
No problem - happy to help clarify anything. Cheers!
I've compiled a list of angular directives according to their priorities.
Also, I've included terminal property for each directive that asserts it
Hope it helps someone
Very cool! One thing, though - I believe that ngSwitch is actually at priority:0. It's only the ngSwitchWhen / ngSwitchDefault that is now at priority:1,200.