【发布时间】:2020-06-09 19:24:53
【问题描述】:
在检查了几个回复之后,我在这里提出这个问题,因为我在绑定“mat-select”输入时遇到了一些问题。
这是component.ts文件中的代码
selectedIndustry : any;
constructor(private industrysectorService: IndustrySectorService, private _formBuilder: FormBuilder) {}
ngOnInit() {
this.industrysectorService.get().subscribe((response: IResponse<IIndustrySector[]>) => {
if (response.isSuccessful) {
this.industries = response.result.list;
} else {
this.industries = [];
}
});
this.selectedIndustry = this.industries[0];
这在 componente.html 文件中。
<mat-label>Industry Sector</mat-label>
<mat-select required type="number" [(ngModel)]="selectedIndustry" [ngModelOptions]="{standalone: true}">
<option *ngFor="let industry of industries" [ngValue]="industry.id">{{industry.industrySectorName}}</option>
</mat-select>
控制台中的错误信息是:
EngagementDetailsComponent.html:43 ERROR Error: Cannot find control with unspecified name attribute
at _throwError (forms.js:3357)
at setUpControl (forms.js:3181)
at FormControlDirective.ngOnChanges (forms.js:7102)
at checkAndUpdateDirectiveInline (core.js:31906)
at checkAndUpdateNodeInline (core.js:44367)
at checkAndUpdateNode (core.js:44306)
at debugCheckAndUpdateNode (core.js:45328)
at debugCheckDirectivesFn (core.js:45271)
at Object.eval [as updateDirectives] (EngagementDetailsComponent.html:48)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:45259)
并且数据绑定不起作用。 变量:“selectedIndustry”和“industries”已从数据库中正确填充。 我检查了this 示例,但我无法确定问题出在哪里。 谢谢!
【问题讨论】:
标签: angular select binding angular-material angular8