mat-select returns 在 SelectionChange() 上未定义

mat-select returns undefined on SelectionChange()

我在 (selectionChange) 事件上有 mat-select 我收到未定义的值 $event.value。它 returns 第一个 mat-option.mat 选项的正确值 'All' 它给出了 undefined

 <mat-form-field>
            <mat-select [(value)]="regionOption" (selectionChange)="regionSelectionChange($event)"
              placeholder="Region">
              <mat-option *ngFor="let region of regions" [value]="region.location_name">{{region.location_name}}</mat-option>
              <mat-option [value]="All" >All</mat-option>
            </mat-select>
 </mat-form-field>

//ts

regionSelectionChange(regionName)
{
     console.log(regionName);
}

将您的值绑定从 [value] 更改为值

<mat-option value="All">All</mat-option>

我会选择这个:

TS代码:

export class FormFieldOverviewExample {

  regions: any[]= [{'location_name':"Pune"},{'location_name':"Mumbai"}];

  constructor(){
    this.regions.push({'location_name':"All"}); -- Will add a value in the constructor
  }
  regionSelectionChange(regionName) {
    console.log(regionName.value);
  }
}

HTML代码:

<mat-form-field>
    <mat-select [(value)]="regionOption" (selectionChange)="regionSelectionChange($event)" placeholder="Region">
        <mat-option *ngFor="let region of regions" [value]="region.location_name">{{region.location_name}}
    </mat-option>
    </mat-select>
</mat-form-field>

Working-Demo