<p ng-repeat="program in programs">
<a class="pBlock" href="#"></a>
</p>
There are 10 pieces of data in programs. Now I want to add a specific attribute command rightCtrl
to the a tag of the 5th and 10th items to achieve the following effect
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#" rightCtrl></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#"></a></p>
<p><a class="pBlock" href="#" rightCtrl></a></p>
How to achieve this
ng-repeat
指令會(huì)遍歷programs
集合,然后給集合中的每一個(gè)元素都生成一個(gè)模板實(shí)例,集合programs
中的每個(gè)元素都會(huì)被賦予自己的作用域和模板,同時(shí)每個(gè)每個(gè)模板實(shí)例的作用域都會(huì)暴露出一些屬性。
你可以利用其中的$index
Properties to accomplish what you want.
I have an example here. You can take a look at it, determine which one of the instructions you want to add, and then write your code. demo
You may have to go through a firewall to view the code. If you can’t browse it, I can take a screenshot for you.
<p ng-repeat="program in programs">
<a class="pBlock" href="#" ng-if='$index == 4' rightCtrl></a>
<a class="pBlock" href="#" ng-if='$index != 4'></a>
</p>