I am working on a project where I need to implement search with multi select drop down. When I added below code, I am able to search but my previously selected value is disappearing after new search.
Below is the code snippet.
HTML:
<mat-form-field appearance="fill">
<mat-label>Providers</mat-label>
<mat-select multiple [formControl]="providers">
<mat-select-trigger>
{{providers.value }}
</mat-select-trigger>
<input type="text" autocomplete="off" matInput placeholder="Search By Provider" #multiUserSearch (
input)="onInputChange()">
<mat-option *ngFor="let provider of provider " [value]="provider.PROV">{{provider.PROV}}
</mat-option>
</mat-select>
TS FILE:
onInputChange(){
console.log(this.multiUserSearchInput.nativeElement.value);
const searchInput=this.multiUserSearchInput.nativeElement.value?
this.multiUserSearchInput.nativeElement.value.toLowerCase():'';
this.provider=this._provider.filter(u=>{
const PROV:string=u.PROV.toLowerCase().;
return PROV.indexOf(searchInput) > -1;
});
}
Can you please help me.