I spent a lot of time solving this problem and failed.(我花了很多时间解决这个问题,但失败了。)
I want to select to display the name and get the id.(我想选择显示名称并获取ID。) The problem is, as soon as a value is selected, the number (id) of that value is displayed.(问题是,一旦选择了一个值,就会显示该值的数字(id)。) My code:(我的代码:)
<mat-form-field class="example-full-width">
<input
matInput
placeholder="Search your product"
formControlName="id"
[matAutocomplete] = "auto">
<mat-autocomplete #auto="matAutocomplete" >
<mat-option *ngFor="let option of allProducts; let i = index" [value]="option.id" >
{{ option.name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
I tried to create a function (onSelectionChange) but could not display the name and take the value as (id)(我试图创建一个函数(onSelectionChange),但无法显示名称,并将值设为(id))
ask by AleksandarMihailovic translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…