Angular.js: Support expressions on ng-switch-when

Created on 14 Dec 2013  路  5Comments  路  Source: angular/angular.js

I tried myself to do this and I was able to implement it but I couldn't make the test to work. Please refer to this Stackoverflow question: http://stackoverflow.com/questions/20482653/testing-angularjs-scope-variables

misc core breaking change feature

Most helpful comment

This is not going to happen, the main reason is that allowing expressions into ngSwitchWhen will requiere a watch on the expression, and this defeats the entire purpose of ngSwitchWhen

What about interpolated values which are resolved once (and not watched)? E.g.:

<p ng-switch="error.code">
  <p ng-switch-when="{{errors.someErrorCode1}}"></p>
  <p ng-switch-when="{{errors.someErrorCode2}}"></p>
  ...
  <p ng-switch-default></p>
</p>

I have string constants in my errors object and want to use those strings to match against with ng-switch-when. Is this not possible? I don't think ng-messages has support for a default.

All 5 comments

This is not going to happen, the main reason is that allowing expressions into ngSwitchWhen will requiere a watch on the expression, and this defeats the entire purpose of ngSwitchWhen

This is not going to happen, the main reason is that allowing expressions into ngSwitchWhen will requiere a watch on the expression, and this defeats the entire purpose of ngSwitchWhen

What about interpolated values which are resolved once (and not watched)? E.g.:

<p ng-switch="error.code">
  <p ng-switch-when="{{errors.someErrorCode1}}"></p>
  <p ng-switch-when="{{errors.someErrorCode2}}"></p>
  ...
  <p ng-switch-default></p>
</p>

I have string constants in my errors object and want to use those strings to match against with ng-switch-when. Is this not possible? I don't think ng-messages has support for a default.

Yeah, would be awesome to have just once-resolved values. Similar use-case for me.

Also useful for supporting TypeScript enums exposed via controller

Even an NgIf/NgElse would solve this, I think.

Was this page helpful?
0 / 5 - 0 ratings