-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngSwitch): Allow multiple case matches for one element #3516
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
This PR adds 60 bytes to the minified build. Edit: Mary Poppins is now happy :) |
👍 |
Arguably this has a breaking change in the case the someone wanted to match to a string that was wrapped in square brackets. |
Now you can also use an array in `ng-switch-when`, which allows specifying multiple values for the same element. Values will be evaluated within the scope when using the array notation. I.e. `ng-switch-when='[1, 3, 'hello', 5-3]'` Each element will switch only once even if there are multiple matches in the same element. BREAKING CHANGE: Previously `ng-switch-when` expressions that matched against square brackets strings won't work anymore. The fix is encapsulate the string into a one-element array. I.e. before `ng-switch-when='[hi]'`, now `ng-switch-when="['[hi]']"` Closes angular#3410
@petebacondarwin Thanks, you're right. I've updated the commit message to address this. |
Hi, even when I do see some value in this enhancement, the use of $eval gives a big potential for abusing of this feature. Why not limit this to JSON? |
The idea behind using Anyway, I could switch to |
If there is a general consensus that $eval is better, I am fine with that. Anyhow, doing an $eval has some unexpected side-effects Say |
Either way I think it's a valuable feature. I hope it gets reviewed soon... |
Could someone from the team tag this PR? Thank you! |
@lrlopez backlog more or less means its on our list of things to get to, but it may not be a priority for this release (which is mostly revolving around migrating over to the new doc generator). But, just to give it some quick review, the issue here is that it sort of says "hey, sometimes this attribute is a plain string, and sometimes it's treated as an angular expression", despite not actually using the expression parser. I think we could have a better solution which doesn't add any inconsistency by having a separate attribute which is parsed as an expression, instead. |
Caitlin, thanks for your reply. I found the backlog milestone description just after posting. I agree that a possible solution is having a separate attribute, does everybody agree? The new attribute could be named |
any good news for this issue? |
@atian25, I'm just waiting for someone from the core team to give me the green light about the new attribute... |
Why not use a comma-separated list? It's to easy to implement and understand |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516
Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516
Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516
#10798 is the way forward, I hope we can get it into 1.5 |
…SwitchWhenSeparator Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516 Closes angular#10798
…SwitchWhenSeparator Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516 Closes angular#10798
…SwitchWhenSeparator Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516 Closes angular#10798
…SwitchWhenSeparator Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516 Closes angular#10798
…SwitchWhenSeparator Adds an optional attribute `ngSwitchWhenSeparator` that allows multiple tokens to match a given `ngSwitchWhen`. Closes angular#3410 Closes angular#3516 Closes angular#10798
This does not seem to be working in angular 1.5.8 !!! |
When is the new version expected to be published |
It should have been released by the end of next week (probably sooner). |
Now you can also use an array in
ng-switch-when
, which allows specifying multiple values for the same element. Values will be evaluated within the scope when using the array notation.I.e.
ng-switch-when="[1, 3, 'hello', 5-3]"
Each element will switch only once even if there are multiple matches in the same element.
BREAKING CHANGE: Previously
ng-switch-when
expressions that matched against square brackets strings won't work anymore. The fix is encapsulate the string into a one-element array.I.e. before
ng-switch-when='[hi]'
, nowng-switch-when="['[hi]']"
Closes #3410