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)
你应该使用
formControlNameinmat-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)
| 归档时间: |
|
| 查看次数: |
1835 次 |
| 最近记录: |