我正在尝试使用两个ng-repeat编写以下代码。
<td class="researched" colspan="2" ng-repeat="tech in userCtrl.chosenTechs1" title="{{tech.name}}">{{tech.name}}</td>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech" ng-if="5 > userCtrl.chosenTechs1.length" >6</td>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech" ng-if="4 > userCtrl.chosenTechs1.length" >6</td>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech" ng-if="3 > userCtrl.chosenTechs1.length" >6</td>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech" ng-if="2 > userCtrl.chosenTechs1.length" >6</td>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech" ng-if="1 > userCtrl.chosenTechs1.length" >6</td>
我试过这个,但没有工作
<td class="researched" colspan="2" ng-repeat="tech in userCtrl.chosenTechs1" title="{{tech.name}}">{{tech.name}}</td>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech" ng-repeat="5 > $index">6</td>
基本上我想要的是获得userCtrl.chosenTechs1
的长度,如果长度小于5,我想重复它直到达到5
答案 0 :(得分:1)
ng-repeat="5 > $index"
这是一种糟糕的做法。您需要有另一个列表/数组来迭代。准备控制器中的第二个数组,如果第一个数组的长度大于或等于5,则使其为空,因此在这种情况下它将消失。你不应该在html中显示哪些数据包含太多魔法,该逻辑属于你的控制器。
答案 1 :(得分:0)
你可以使用ng-repeat-start和ng-repeat-end作为td&#39; s包装器(作为黑客)
<td class="researched" colspan="2"
ng-repeat-start="tech in userCtrl.chosenTechs1"
title="{{tech.name}}">{{tech.name}}</td>
<div ng-repeat-end>
<td class="available" colspan="2" title="6 trade needed to learn level 1 tech"
ng-repeat="5 > $index">6</td>
</div>