Filter on a mat-select Filter on a mat-select angular angular

Filter on a mat-select


You have to assign the returned filtered list.

 filterListCareUnit(val) {    console.log(val);    this.listCareUnits = this.listCareUnits.filter((unit) => unit.label.indexOf(val) > -1);  }

But in order not to lose the data of your initial array, it will be better to use another array for processing that will always contain your initial set of data.

anotherArray = this.listCareUnits;filterListCareUnit(val) {        console.log(val);        this.listCareUnits = this.anotherArray.filter((unit) => unit.label.indexOf(val) > -1);      }


I know that this has been answered, but you could also have used "mat-select-filter".

https://www.npmjs.com/package/mat-select-filter

Hopefully this will help someone else.