-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ngSwitchWhen element eats ngRepeat's child scope #8235
Comments
well it's pretty clearly not a behaviour which makes sense to a programmer, but I think it's somewhat more complicated than described here. @petebacondarwin wdyt? |
I think this is a bug. We had to change |
@petebacondarwin does the change pass tests there? if so we should probably fix this soon |
I'll check today and put together a fix
|
Meta: @petebacondarwin @caitp Aren't we supposed to only label with one of |
these are qualitative measures, and they're all applicable here. |
Really, I need no idea. https://github.com/angular/angular.js/blob/master/TRIAGING.md doesn't mention it, and that's also not how I understood it when Brian explained it to me. |
I should add, "in my opinion" --- I don't believe "broken expected use case" is any more "severe" than "confusing" or "inconvenient". The fact is, this is a broken expected use case (we know this because it seems totally natural to want to use it this way), it's confusing because it's kind of hard to even reason about why this doesn't work as expected, and it's inconvenient because it requires you to work around the limitations of the compiler with hacks. I believe each of these are qualities applicable to this issue, and I would not be able to say that any of them are more severe than any of the others. But really, label it however you like --- these seem reasonable to me, I don't care a whole lot if we take some out |
If an ngSwitchWhen or ngSwitchDefault directive is on an element that also contains a transclusion directive (such as ngRepeat) the new scope should be the one provided by the bound transclusion function. Previously we were incorrectly creating a simple child of the main ngSwitch scope. Closes angular#8235
@petebacondarwin I think that the version from #8235 (comment) is problematic as making it work just for this case gives some false hope that this will work for all cases and that it works like what people expect from |
To make this case work as expected, then we need to make the priority of |
meta: I label with just the "highest severity." The prioritization dashboard assumes you do this. If something is a "broken expected use," then it's almost assuredly going to be "confusing" to developers and also "inconvenient." Of course these qualitative measures are not mutually exclusive, but the idea is that cases where something doesn't work when it reasonably seems like it should are worse than cases where it's somewhat unclear why something works a certain way. Put another way, I consider flagrant violations of a developers expectations to be more severe than edge cases with unexpected behavior. I amended the triaging doc with these notes. If anyone wants to continue the discussion of our triaging process, let's open a new issue for that. |
Thanks @lgalfaso - I will add a test and fix up. I believe that both fixes are needed, no? |
@petebacondarwin yes, both fixes are needed |
@lgalfaso - I can't see where you changed that to make it work in that plunk?? |
Oh, OK, so you changed ngRepeat priorty from 1000 to 700? |
@petebacondarwin change the priority of |
And |
The question is will that break some other use case? I can't think of one since we don't allow ngSwitchWhen to take dynamic values, so people wouldn't be able to generate a bunch of different |
I can't think of anything that will break (and as you mention, the fact that |
Actually this whole thing is broken if you have :-( |
@petebacondarwin it looks like |
Yes I agree I was just doing that refactoring :-) |
If an ngSwitchWhen or ngSwitchDefault directive is on an element that also contains a transclusion directive (such as ngRepeat) the new scope should be the one provided by the bound transclusion function. Previously we were incorrectly creating a simple child of the main ngSwitch scope. Closes angular#8235
Closing in favour of #8244 |
If an ngSwitchWhen or ngSwitchDefault directive is on an element that also contains a transclusion directive (such as ngRepeat) the new scope should be the one provided by the bound transclusion function. Previously we were incorrectly creating a simple child of the main ngSwitch scope. BREAKING CHANGE: ** Directive Priority Changed ** - this commit changes the priority of `ngSwitchWhen` and `ngSwitchDefault` from 800 to 1200. This makes their priority higher than `ngRepeat`, which allows items to be repeated on the switch case element reliably. In general your directives should have a lower priority than these directives if you want them to exist inside the case elements. If you relied on the priority of these directives then you should check that your code still operates correctly. Closes angular#8235
Scope:
HTML:
Fiddle: http://jsfiddle.net/y68sy/1/ (http://jsfiddle.net/PqLmp/)
Expected output:
Actual output:
So the ngRepeat works in the sense that the element is repeated, but the inner scope is wrong; it does not contain the values that ngRepeat puts into it.
This happens because ngSwitch creates a new child scope that inherits from the ngSwitch's scope, not from the ngSwitchWhen's scope:
angular.js/src/ng/directive/ngSwitch.js
Line 169 in e8066c4
I'm not sure if this is expected behaviour, or whether it can be fixed without breaking something else.
The text was updated successfully, but these errors were encountered: