How to use ng-switch in ng-repeat?

Any idea how to use ng-repeat and ng-switch together?

  • I have an issue when I am trying to use ng-options and ng-switch together in AngularJS. Any idea how to use ng-repeat and ng-switch together?

  • Answer:

    Declare an on directive on your ng-repeat like so: <div ng-repeat="..." ng-switch on="item.itemType" > Then inside your repeater you can evaluate the expression inside the on directive like so: <my-type ng-switch-when='1' > ng-switch-when will be evaluated against the on directive in the repeater. If the statement evaluates to true, it will be rendered. In this example item.itemType would need to have a value of 1 to be rendered out. For ng-options however using an ng-switch doesn't make any sense as you can't include any custom html inside a select. If you need a filter or a group by you can do that in the ng-options expression directly. See the docs here: https://docs.angularjs.org/api/ng/directive/ngOptions

yido at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.