8

我的 HTML 代码是

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

哪个不是绑定数据...(存在 TD 和文本,但绑定属性值为空)

如何一次使用 ng-switch-when 和 ng-repeat?

提前致谢

4

2 回答 2

28

ng-switch 要求父母有一个

ng-switch on="variableName"

和孩子们

ng-switch-when="stuff1" 

使用 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>

您的 ng-repeat 集合可能如下所示:

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

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

于 2014-05-06T13:15:15.123 回答
2

这是设计使然。请参阅https://stackoverflow.com/a/15434085/1264360。基本上要修复,您需要在 ng-repeat 上方的元素中使用 ng-switch-when。

于 2014-05-06T13:40:46.863 回答