Orderi...">

Ng-switch-when with ng-repeat

My HTML code

<tr ng-switch-when="true" ng-repeat="onlineCredentials in onlineCredentialDetails" > <td> <span>Ordering Mode: </span>{{onlineCredentials.mode}}<br /> <span>Intermedtiary Group: </span>{{onlineCredentials.name}} </td> <td> <span>Website: </span>{{onlineCredentials.webSite}} </td> <td > <span>Username / Password</span> <div ng-repeat="cred in onlineCredentials.loginDetails"> -&nbsp;{{cred.userName}}&nbsp;/&nbsp;{{cred.password}} </div><br /> </td> </tr> 

Which is optional data ... (TD s and text are present, but the values ​​of the binding properties are empty)

How to work with ng-switch-when and ng-repeat at a time?

Thank you in advance

+6
source share
2 answers

This is by design. See fooobar.com/questions/486673 / .... Basically, to fix you need to have an ng switch - when in the element above is ng-repeat.

+1
source

ng-switch requires the parent to have

 ng-switch on="variableName" 

and for children -

 ng-switch-when="stuff1" 

Ng-repeat example

 <div ng-repeat="value in values" ng-switch on="value.color"> <div ng-switch-when='blue'>Blue</div> <div ng-switch-when='green'>Green</div> <div ng-switch-when='orange'>Orange</div> </div> 

and your collection for ng-repeat might look like this:

 $scope.values = { one: {color: 'blue', worth: 2}, two: {color: 'green', worth: 3}, three: {color: 'orange', worth: 4}, } 

http://plnkr.co/edit/YavzpaPUBaBQNA0pHMPN?p=preview

+22
source

All Articles