Html中的增量ng重复索引值
我想在Html中的增量ng重复索引值,html,angularjs,Html,Angularjs,我想在ng repeat中增加$index的值。例如: <div ng-repeat:x in ProductList"> <label>{{x}}</label> // if x = 1 x++; // this is the line i need <label style="color:red">{{x}}</label> // x index should be equal to 2 x+
ng repeat
中增加$index
的值。例如:
<div ng-repeat:x in ProductList">
<label>{{x}}</label> // if x = 1
x++; // this is the line i need
<label style="color:red">{{x}}</label> // x index should be equal to 2
x++; // this is the line i need
<label style="color:blue">{{x}}</label> // x index should be equal to 3
</div>
您可以简单地执行以下操作:
<div ng-repeat="product in ProductList">
<label>{{$index}}</label>
<label style="color:red">{{$index + 1}}</label>
</div>
{{$index}}
{{$index+1}}
如果我正确理解了您的问题(这很难理解),您希望对ng repeat
中的偶数和奇数索引执行不同的操作。您可以使用ng repeat
中的特殊属性$偶数
和$奇数
<div ng-repeat="x in ProductList">
<label ng-if="$odd">{{x}}</label>
<label ng-if="$even" style="color:red">{{x}}</label>
</div>
{{x}
{{x}
如果这对您没有帮助,请尝试给出一个您期望的输出示例。您正在尝试为数组中的每个项目以diff元素打印索引值
我的建议是创建一个自定义指令,并在不同的元素上使用它。这里是“label”,我们增加索引的计数。对不起,不清楚您在问什么。您想要实现什么?请分享您想要的输出,见下面的回答。这就是我所需要的。结果是不是像1,3,5,7
?你能告诉我你的要求吗。也许我们可以向您推荐最佳解决方案。第二次将从index=3开始?@Eliad您能更具体地说明您真正想要做什么吗?可能更具描述性。您是指产品[$index]和产品[$index+1]谢谢。如果你没有正确地解释你想做什么,那么没有人能帮助你。通常,在你面临问题的同时,最好解释一下你想要实现什么。其他人可能对如何以其他方式实现相同的结果有更好的想法。谢谢,但是没有。我所需要的只是在运行REPEATNG时增加索引。您能解释更多吗?我只是简单地使用ng repeat作为Loop,这是我建议你做的,像这样的我已经创建了一个示例plunker供你参考,希望它能帮助你实现一些你需要的东西,