kongshem
kongshem

Reputation: 332

Extract specific element from ng-repeat

I have a list where I display the content of a list using angularjs, like this:

<ul>
    <li ng-repeat="result in uploadLogObject[fileUpload.id].log track by $index">
      <ul>
        <div data-ng-show="result">{{result}}</div>
      </ul>
    </li>
</ul>

This means that I get a list like this:

* Some data1
* Some data2
* Some data3
* Some data4

Is it possible to take e.g the first element of the list and place outside of the list so that my list is displayed like this?

Some data1
* Some data2
* Some data3
* Some data4

I would guess you would have to do a separate ng-repeat="result in uploadLogObject[fileUpload.id].log track by $index" before the ng-repeat with the list and then display the first content somehow like this? <div data-ng-show="result">{{result}}[0]</div>

Am I wrong or on the right track here?

Upvotes: 0

Views: 295

Answers (1)

Alexandre Nucera
Alexandre Nucera

Reputation: 2223

The documentation of ngRepeat provides a way to do this using ng-repeat-start and ng-repeat-end. :

  <div ng-repeat-start="item in items" ng-if="$first">
    Header {{ item }}
  </div>

  <li ng-repeat-end>
    body {{ item }}
  </li>

Upvotes: 1

Related Questions