Kirill Kaysarov
Kirill Kaysarov

Reputation: 13

ng-repeat, $index and offset problems?

<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>

How i can use $index for offset first X items? {{streamer.imageUrl[$index+4}} - work uncorrectly. Or i must write filter for this action?

Upvotes: 0

Views: 507

Answers (1)

Mark Rajcok
Mark Rajcok

Reputation: 364677

ng-switch can be used with $index to allow ng-repeat items to have different 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>

Upvotes: 1

Related Questions