I use angular 6 and I would like to filter the results of an async pipe, before rendering them in the UI.
Here is my code right now
this.results = this.form.get('name').valueChanges.pipe(
filter(formdata => formdata.name.length > 0),
switchMap( formdata => this.service.getNames(formdata.name))
);
and the template
<div *ngIf='results | async ; let items'>
<div *ngFor='let item of items'>{{item.id}} {{item.name}} </div>
</div>
From the pipe I get some ids and names. I already have an array of ids. I would like to filter the ids of the pipe and not render the ones that are already in the array.
So, here is what I try to do.
array = [{id:1,name:'one'},{id:2,name:'two'}];//I already have this
new version of filter in pipe
this.results = this.form.get('name').valueChanges.pipe(
filter(formdata => formdata.name.length > 0),
switchMap( formdata => this.service.getNames(formdata.name)) ,
filter(checkIfResultIdInArray())//pseudocode
);
Assume that checkIfResultIdInArray
is I function I created. Filters and returns all the ids that are not in the array
. So the ids/names that end up in the template are not the {id:1,name:'one'},{id:2,name:'two'}
.
Or maybe I can filter in the template somehow?