AngularJS ng-repeat列

时间:2016-04-28 08:37:25

标签: angularjs

我有两个div,类col-left和col-right。

如何使用ng-repeat

实现以下目标
<span ng-repeat="value in items">
<div>
   <div class='col-left'>{{val.content}}</div>
   <div class='col-right'>{{val.content}}</div> 
</div>
</span>

2 个答案:

答案 0 :(得分:0)

<span ng-repeat="value in items track by $index">
<div>
   <div class="col-left" ng-if="$index % 2 != 0">{{value.content}}</div>
   <div class="col-right" ng-if="$index % 2 == 0">{{value.content}}</div> 
</div>
</span>

或者:

<span ng-repeat="value in items track by $index">
        <div>
           <div ng-class-odd="'col-left'" ng-class-even="'col-right'">
               {{value.content}}
           </div>
        </div>
   </span>

希望它有所帮助。

答案 1 :(得分:0)

我认为这是更好的方法

<span ng-repeat="value in items track by $index">
    <div class="{'col-left':$odd, 'col-right':$even}">{{value.content}}</div>
</span>