Home > other >  How to remove or hide mat-option after selection in mat-select
How to remove or hide mat-option after selection in mat-select

Time:09-23

I have this table using mat-table and I'm adding a dynamic row on it by clicking a button. One of the column of the said table has a drop down using mat-select with a static mat-option. Please visit this enter image description here

Hope you can guide me on how to implement this.

Thanks!

CodePudding user response:

Create a method to get the filtered services in your component something like

getServices(selectedService){
   let selecteServices:any[]=this.form.value?.servicesArr?.map(s=> s.services)||[];
   return this.services.filter(s=> s == selectedService || selecteServices.every(sv=> sv != s))
}

Then use this method to fetch filtered services from UI

 <mat-select #ser formControlName="services" (selectionChange)="onSeviceChange($event, element)">
              <mat-option *ngFor="let service of getServices(ser.value)" [value]="service">
                {{ service }}
              </mat-option>
 </mat-select>

Working demo

  • Related