如何使用角度6在mat-select中获取下拉文本

问题描述 投票:0回答:1

这是我的代码HTML:

<mat-list-item class="primary-imenu-item" role="listitem">
    <mat-select class="form-control" multiple formControlName="statusCode" (selectionChange)="getSelectedOptionText($event)">
        <mat-option *ngFor="let list of statusList" [value]="list.id" checkboxPosition="before">
            {{list.code}}
        </mat-option>
    </mat-select>
</mat-list-item>

TS代码:

getSelectedOptionText(event: MatSelectChange) {
    let selectedData = {
        code: (event.source.selected as MatOption).viewValue,
        value: event.source.value
    };

    console.log(selectedData);
}

在那个'selectedData'中,我得到的代码值是不确定的。我需要从下拉列表中获取代码值。请帮助我。在此先感谢

c# html asp.net angular6 dropdown
1个回答
0
投票

选项值应设置为[value] =“ list.value”

<mat-option *ngFor="let list of statusList" [value]="list.value" 
    checkboxPosition="before">
    {{ list.code }}
</mat-option>
© www.soinside.com 2019 - 2024. All rights reserved.