首页 > 解决方案 > mat-select 在 SelectionChange() 上返回 undefined

问题描述

我有 mat-select on (selectionChange) 事件,我收到 undefined 作为$event.value. 它为第一个 mat-option.mat-option 返回正确的值,其值为 '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);
}

标签: angular-materialangular7

解决方案


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

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


推荐阅读