Filter *ngFor async data

Asked

Viewed 628 times

1

As a filter is applied to a *ngFor async, the *ngFor array comes from an Observable.

lotes$: Observable<Lote[]>;

*ngFor="let lote of (lotes$  | lancamentosFilter:searchText) | async; let i = index"

my filter, but it doesn’t work

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

@Pipe({
    name: 'lancamentosFilter',
    pure: false
})
export class LancamentosFilter implements PipeTransform {

    transform(items: any[], filter: any): any {

        if(items !=null)
        items.forEach(obs => (console.log(obs)));


        if (!items || !filter || !isArray(items)) {
            return items;
        }
        return items.filter(item => item.historico.indexOf(filter.historico) !== -1);
    }
}

1 answer

2


You are using your pipe before async, meaning it is receiving an Observable and not an array.

You must change the order of the Pipes:

(lotes$  | async) | lancamentosFilter:searchText

Browser other questions tagged

You are not signed in. Login or sign up in order to post.