在角度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>
答案 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>