更新时未选择Angular 8材质特定的垫选项

时间:2019-06-07 09:42:41

标签: angular angular-material angular8

在角度8垫选项中,未选择特定选项。 我放置了静态选项,然后工作正常。但是,它不适用于动态垫选项。

<mat-label>Item Category  {{item.category_id}}</mat-label>
<mat-select name="category_id" [(ngModel)]="item.category_id" #category_id="ngModel" required>
<mat-option *ngFor="let cat of categoriesData" [value]="cat.id" >
    {{cat.category_title}}
</mat-option>
</mat-select>

1 个答案:

答案 0 :(得分:0)

我必须解决此问题。这是一个了不起的问题。

我的选项值变量是Int(例如:1),发现ngmodel值是来自服务器api的字符串(例如:“ 1”)

<mat-label>Item Category  {{item.category_id}}</mat-label>
<mat-select name="category_id" [(ngModel)]="item.category_id" #category_id="ngModel" required> // found ngmodel variable value is string from server api (like "1")
<mat-option *ngFor="let cat of categoriesData" [value]="cat.id" > // cat.id variable is int (like: 1)
    {{cat.category_title}}
</mat-option>
</mat-select>