ng-switch-when with ng-repeat

Santhosh picture Santhosh · May 6, 2014 · Viewed 17.3k times · Source

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

Answer

SoluableNonagon picture SoluableNonagon · May 6, 2014

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