0

TS

  @Select(NotificationState.get('onDisplay')) onDisplay$: Observable<Array<Partial<Alert>>>;

HTML

<ng-container *ngFor="let notif of onDisplay$ | async; let i = index">
    <span>{{notif.name}}</span>
  </ng-container?>

the data is:

[{
    name: 'John',
    case: 'CLOSED'
},{
    name: 'Joshua',
    case: 'CLOSED'
},{
    name: 'Carl',
    case: 'NEW'
},{
    name: 'Jen',
    case: 'CLOSED'
}]

I'm using observable and what I'm trying to do is to remove the data which has case: 'CLOSED'. How to remove the item have CLOSED from the array in ngFor?

Panda
  • 365
  • 9
  • 23

2 Answers2

2

You could use *ngIf directive to show only properties with certain condition.

<ng-container *ngFor="let notif of onDisplay$ | async; let i = index">
  <span *ngIf="notif.case !== 'CLOSED'">{{notif.name}}</span>
</ng-container>
ruth
  • 29,535
  • 4
  • 30
  • 57
2

Demo write custom pipe for this

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
  name: 'closedPipe'
})

export class CustomPipe implements PipeTransform {
  transform(row: any[]): any {
      return row.filter(x=>x.case!="CLOSED");       
  }
}
mr. pc_coder
  • 16,412
  • 3
  • 32
  • 54