【发布时间】:2019-02-19 03:30:30
【问题描述】:
我在我的 UI 中使用下拉菜单,但是当我开始使用 [formControl] 时,我收到了错误:
找不到具有未指定名称属性的控件
我在 app.module.ts 中使用 ReactiveFormsModule。
我在 Google 上搜索并发现解决方案是在父 div 中使用 [formGroup],但我不确定如何正确实施,因为我正在从 subscribe 中定义我的 formControl .
myComp.component.html
<div class="exceptional-status">
<select #exceptionalSelect id="excep-status-dropdown" [formControl]="select">
<option disabled value="default">--Exceptional statuses--</option>
<!-- other options here with *ngFor -->
</select>
</div>
myComp.component.ts
select: FormControl;
mySubscription() {
this.myService.myFunct.subscribe(res => {
this.select = new FormControl(res.status)
});
}
【问题讨论】:
-
您的变量声明也错误,请检查角度文档:angular.io/guide/reactive-forms
标签: javascript html angular typescript