角度垫选择下拉列表返回未定义的值

时间:2018-09-11 15:36:24

标签: angular angular6 angular-forms

HTML:

<mat-form-field>
    <mat-select placeholder="Section Types"(selectionChange)="selectSectionType($event)" disableRipple>
<mat-option *ngFor="let type of sectionTypes" [value]="type.value">
              {{type.viewValue}}
            </mat-option>
          </mat-select>
        </mat-form-field>

TS:

sectionTypes: DropDown[] = [
    {value: '0', viewValue: 'Horizontal'},
    {value: '1', viewValue: 'Vertical'}
  ];

selectSectionType(event: any){
    console.log("section type: " + event.target.value);
  }

当我从mat-select下拉列表中选择一个值时,将输入方法selectSectionType,但event.target.value返回未定义。我不知道为什么。

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

选择的值:

selectSectionType(event: any){
    console.log("section type: " + event.value);
}

OR

event.source.value

您有一个对象MatSelect

event.source.MatSelect