ng-switch-when with ng-repeat
Asked Answered
A

2

8

My HTML code is

<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 not binding data... (TD s and text is present but binding property values are empty)

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

Thanks in advance

Alienor answered 6/5, 2014 at 12:41 Comment(0)
S
2

This is by design. Please see https://mcmap.net/q/927660/-ng-switch-and-ng-repeat-on-the-same-element-interfearing. Basically to fix you need to have the ng-switch-when in an element above the ng-repeat.

Sisely answered 6/5, 2014 at 13:40 Comment(0)
P
28

ng-switch requires a parent to have a

ng-switch on="variableName"

and children to have

ng-switch-when="stuff1" 

Example with ng-repeat

<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:

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

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

Python answered 6/5, 2014 at 13:15 Comment(0)
S
2

This is by design. Please see https://mcmap.net/q/927660/-ng-switch-and-ng-repeat-on-the-same-element-interfearing. Basically to fix you need to have the ng-switch-when in an element above the ng-repeat.

Sisely answered 6/5, 2014 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.