-1

I have ng-switch="field.type" for an element containing ng-switch-when but I'd like to have the switch on when it's more than just one field.type.

I would assume something like ng-switch-when="type1 || type2" would work, but it doesn't.

What's the correct way to do this?

Reuben
  • 2,701
  • 6
  • 31
  • 47

1 Answers1

0

You can do solve it by copying the same ng-switch-when element (ie. element with the same content/innerHTML) for every value.

Like this:

<div ng-controller="mainCtrl">
    <div ng-switch="expression">
      <div ng-switch-when="matchvalue1">Item 1</div>
      <div ng-switch-when="matchvalue2">Item 1</div>
      <div ng-switch-when="matchvalue3">Item 3</div>
      <div ng-switch-default>default</div>
    </div>
</div>

http://jsfiddle.net/JoeSham/HB7LU/9201/

Joe Samanek
  • 1,644
  • 12
  • 16
  • Right, but with more code that seems quite inefficient and wrong. – Reuben Dec 15 '14 at 23:54
  • Well this is actually the solution from angularjs docs. I think it is efficient enough, maybe not quite so elegant. If you want an elegant solution, you can create your own ng-switch-directive. – Joe Samanek Dec 16 '14 at 11:41