【发布时间】:2018-07-04 19:31:49
【问题描述】:
我正在尝试在 Angular 5 中实现 select,但我不断得到这个
我已经尝试了许多 StackOverflow 问题,唯一的区别是 - 我的组件位于应用程序中的另一个模块内,该模块最终最终注入到主模块中。我也尝试在内部模块中注入FormsModule。我尝试过导入ReactiveFormsModule,但没有成功。
我已将 FormsModule 添加到这样的导入中
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
declarations: [
...CombineComponents
],
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpClientModule
]
});
这是我的组件标记
<label for="ctn" class="d-inline-block pl-1 semi-bold">Current active number</label>
<select
#selectElem
class="custom-select"
id="ctn"
(change)="onCTNChange(selectElem.value)"
formControlName="state"
>
<option value="" disabled>Choose a state</option>
<option *ngFor="let ctn of availableCTN" [ngValue]="ctn.value">
{{ctn.text}}
</option>
</select>
【问题讨论】:
标签: angular angular-forms