我正在尝试在Angular 5中实现select,但我一直得到这个错误:
我已经尝试了许多StackOverflow的问题,唯一的区别是——我的组件位于应用程序中的另一个模块内,最终被注入到主模块中。我还尝试将FormsModule注入到内部模块中。我尝试导入ReactiveFormsModule,但没有成功。
我已像这样将FormsModule添加到imports中:
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>

[ngModel]也会抛出类似的错误。 - Usman Tahir