0

I am using below code in my application.Here my problem is I have included below code in a every table column header. So when ever I click on mat-select a new currentddvalues will be formed and will be used in *ngFor loop of mat-option.

The problem is when ever I click on one column header, data will be loaded to all column mat-select options, because of this I am not able to persist user selection once clicked on another mat-select.

Can any once help how to restrict this ngFor only once on mat-select or any other suggestion to persist user selection after clicking on other mat-select.

                                            <mat-form-field >
                                              <mat-select  placeholder="Banks" #{{headerName}} (click)=getColumnData(i) multiple>
                                                <!-- <mat-select-search [formControl]="bankMultiFilterCtrl"></mat-select-search> -->
                                               <mat-option #{{headerName}}. (onSelectionChange)="sorton(-1, -1)" id="clearopt">Clear filter</mat-option>
                                                <mat-option *ngFor="let record of currentddvalues " (onSelectionChange)="sorton(i, record)" id={{record}} >
                                                  {{record}}
                                                </mat-option>

                                              </mat-select>
                                            </mat-form-field>

1 Answers1

0

Try like this:

Working Demo

.ts

isClicked:boolean = false

getColumnData(i){
    this.isClicked = true
}

.html

 <mat-select  placeholder="Banks" #{{headerName}} (click)="!isClicked ? getColumnData(): false" multiple>
 </mat-select>
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79