使用具有反应形式的有角材料 mat-select 时出错

iro*_*man 2 angular-material angular angular7 angular-material-7

我正在尝试将角材料 mat-select 与反应形式一起使用,并收到错误消息“没有名称用于表单控件的值访问器:'productUnitofMeasure'”。

其他 FormControl 在这里工作正常,我已经在 app 模块中包含了所有必需的模块。

应用模块:

import {MatFormFieldModule, MatOptionModule, MatSelectModule, MatInputModule} from '@angular/material';

imports:[
MatFormFieldModule,
MatOptionModule,
MatSelectModule,
MatInputModule,
ReactiveFormsModule]
Run Code Online (Sandbox Code Playgroud)

模板:

<mat-form-field>
<mat-select placeholder="Unit Type">
    <mat-option *ngFor="let unitType of unitList" matInput formControlName="productUnitofMeasure" [value]="unitType.unitId">{{unitType.unitDescription}}</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)

成分:

this.productForm = new FormGroup({
  productName: new FormControl,
  productDescription: new FormControl,
  productPrice: new FormControl,
  productAvailableQuantity: new FormControl,
  productUnitofMeasure: new FormControl //this is the only control giving me an error.


});
Run Code Online (Sandbox Code Playgroud)

Sun*_*ngh 5

你应该使用formControlNamein mat-selectnot inmat-option

<mat-form-field>
<mat-select placeholder="Unit Type" formControlName="productUnitofMeasure" >
    <mat-option *ngFor="let unitType of unitList" matInput [value]="unitType.unitId">{{unitType.unitDescription}}</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)