samedi 7 mars 2020

how to show multiple selected options in mat select (check box)

i have a edit form in which i want to show selected options which are fetch from database. following is html code

<mat-select placeholder="Select Year" [compareWith]="compareFn" formControlName="security_deposite_for" multiple>
        <mat-option *ngFor="let year of security_deposite_for_yr; let i = index;" [value]="year.val"
          (click)="tosslePerOne(i)">
          
        </mat-option>
        <mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
      </mat-select>

this is my function in which i get values from database

getSecurityDepositeDetailForEdit(bid_id){
this.abcSer.getgetSecurityDepositeDetail(bid_id).subscribe(
  res => {
    console.log('res in sec deposite',res);
    res.forEach(element => {
        this.checkedOptions.push({
          val: element.sec_deposite_year,
          viewValue: element.sec_deposite_year,
        });
    });
  },
  err => {
    console.log('err in sec details',err);
  }
)

}

following is compare function

compareFn(security_deposite_for_yr,checkedOptions) {
console.log('security_deposite_for_yr 1',security_deposite_for_yr);
console.log('checkedOptions',checkedOptions);
return security_deposite_for_yr && checkedOptions ? security_deposite_for_yr.val === checkedOptions.val : security_deposite_for_yr === checkedOptions;
}

in console security_deposite_for_yr has values, but checkedOptions does'nt show any value.

so how to show selected values in mat multi select




Aucun commentaire:

Enregistrer un commentaire