ng-repeat,$ index和offset问题?

时间:2013-03-03 08:16:34

标签: javascript angularjs

<ul class="stream-informer-short-list">
  <li class="stream-informer-short-list-item" ng-repeat="streamer in streamerItems">
     <a href="stream.html"><img src="{{streamer.imageUrl}}"></a>
  </li>
</ul>

我如何使用$ index来抵消前X个项? {{streamer.imageUrl [$ index + 4}} - 工作不正确。 或者我必须为此操作编写过滤器?

1 个答案:

答案 0 :(得分:1)

ng-switch可与$ index一起使用,以允许ng-repeat项目具有不同的HTML:

<ul class="stream-informer-short-list">
  <li class="stream-informer-short-list-item" ng-repeat="streamer in streamerItems">
     <span ng-switch on="$index <= 4">
       <a ng-switch-when="true" href="stream.html">
          <img src="{{streamer.imageUrl[$index+4]}}"></a>
       <a ng-switch-default href="stream.html">
          <img src="{{streamer.imageUrl[$index]}}"></a>
     </span>
  </li>
</ul>