Norfeldt
Norfeldt

Reputation: 9678

Angular filter and $index

I need some help figuring out how to make avoid repeating a divider while applying a filter.

<div class="list">
      <div ng-repeat="record in records| orderBy : 'Type' | filter: query">
        <div class="item item-divider item-dark" 
         ng-if="record.Type != records[$index-1].Type">
          {{record.Type}}
        </div>
        <div class="card">
        ...

Working fine when not filtering

success

Not working when filtering

failed

Upvotes: 0

Views: 346

Answers (1)

jbmilgrom
jbmilgrom

Reputation: 23211

Staying with your setup, I think the simplest way to go is:

<div class="list">
  <div ng-repeat="record in filteredRecords = (records | orderBy : 'Type' | filter: query)">
    <div class="item item-divider item-dark" 
     ng-if="record.Type != filteredRecords[$index-1].Type">
      {{record.Type}}
    </div>
    <div class="card">
    ...

Note the newly defined filteredRecords

Upvotes: 1

Related Questions