0

Is there a pipe/ syntax that let's you iterate over a collection in reverse order using the ngFor directive ?

Aman Gupta
  • 7,883
  • 5
  • 16
  • 24

1 Answers1

3

Create custom filter:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'reverse',
  pure: false
})
export class ReversePipe {
  transform(value) {
    return value.slice().reverse();
  }
}

Use in your template:

<li *ngFor="let row of collection | reverse">
    ...
</li>

Hope it will work for you.

Avnesh Shakya
  • 3,828
  • 2
  • 23
  • 31