我的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">
- {{cred.userName}} / {{cred.password}}
</div><br />
</td>
</tr>
这不是绑定数据…(TD和文本存在,但绑定属性值为空)
如何同时使用ng-switch-when和ng-repeat ?
Thanks in advance
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 =预览
这是设计。请参阅https://stackoverflow.com/a/15434085/1264360。基本上,要修复这个问题,你需要在ng-repeat元素的上方设置ng-switch-when