0

我正在学习 AngularJS,我只想div在.$index == 2

这是我的代码

<span ng-repeat="element in [0,1,2,3]">
    <div ng-if="$index == 2"> 
        <div> I'm the div
    </div>                  
    <div>
         My element: {{element}} - Index: {{$index}}
    </div>      
    <div ng-if="$index == 2"> 
        </div> I'm the /div
    </div>
</span>  

Fiddle:http: //jsfiddle.net/2prRw/3/

问题

“我的元素:0”、“我的元素:1”和“我的元素:3”从不显示。

结果是:

I'm the div
My element: 2 - Index: 2
I'm the /div

谢谢!

编辑

预期结果是:

   span
     div
         My element: 0
     /div
     div
         My element: 1
     /div
     div
         div
            My element: 2
         /div
     /div
     div
         My element: 3
     /div
   /span
4

1 回答 1

2

解决方法,但会导致一些重复:

<span ng-repeat="element in [0,1,2,3]">
    <div ng-if="$index == 2"> 
        <div> I'm the div
            <div>
                My element: {{element}} - Index: {{$index}}
            </div>      
        </div> I'm the /div
    </div>
    <div ng-if="$index != 2">
        My element: {{element}} - Index: {{$index}}
    </div>
</span>  

JSFiddle

于 2014-01-09T15:47:31.107 回答