小编use*_*118的帖子

Angular4 matAutocomplete在选择项目时不显示值但显示ID

当我在下面的 matAutocomplete formControl 中选择一个项目时,我总是得到 ID,而不是下拉列表中显示的值。

当我将 [value]="baseCoin.ID" 更改为 [value]="baseCoin.Abbr" 时,当我选择一个项目时会显示正确的字符串,但是,我需要 (ngModelChange) 事件将 baseCoin.ID 返回到一个方法,而不是 baseCoin.Abbr。

<mat-form-field>
    <input matInput placeholder="Base Coin" aria-label="Base Coin" [matAutocomplete]="basecoin" [formControl]="baseCoinCtrl" [(ngModel)]="newTrade.BaseCoin.Abbr" (ngModelChange)="populateMarketCoins( $event )">
    <mat-autocomplete #basecoin="matAutocomplete">
        <mat-option *ngFor="let baseCoin of filteredBaseCoins | async" [value]="baseCoin.Abbr">
            {{baseCoin.Abbr | uppercase}}
        </mat-option>
    </mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

帮助表示赞赏。谢谢。

angular-material2 angular angular4-forms mat-autocomplete

2
推荐指数
1
解决办法
6227
查看次数