yido
yido

Reputation: 307

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?

Upvotes: 0

Views: 94

Answers (1)

Willem D'Haeseleer
Willem D'Haeseleer

Reputation: 20180

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

Upvotes: 1

Related Questions