我一直在研究我的应用。 我想使用ReactiveFormsModule模块,但我得到了
错误:意外的模块' ReactiveFormsModule'由模块' AppModule'
声明
我已将角度/表格安装到我的项目中,但似乎没有任何效果。 有什么想法吗?
我的component.ts文件
import {Component} from '@angular/core';
import {FormGroup, FormControl} from '@angular/forms';
@Component({
selector: 'app-crm-search',
templateUrl: './crm-search.component.html',
styleUrls: ['./crm-search.component.css'],
})
export class CrmSearchComponent{
constructor() {
}
userForm = new FormGroup({
searchTerm: new FormControl()
});
onSubmit(){
console.log(this.userForm.value());
}
}
我的app.module.ts
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';
import {AlertModule} from 'ng2-bootstrap';
import {Select2Module} from 'ng2-select2';
import {RoutingModule} from './routing.module';
import {ReactiveFormsModule} from '@angular/forms';
import {AppComponent} from './app.component';
import {NavBarComponent} from './components/nav-bar/nav-bar.component';
import {IndexComponent} from './index/index.component';
import {CrmIndexComponent} from './crm/crm-index/crm-index.component';
import {CrmSearchComponent} from './crm/crm-search/crm-search.component';
import {CrmSearchResultComponent} from './crm/crm-search-result/crm-search-result.component';
@NgModule({
declarations: [
AppComponent,
NavBarComponent,
IndexComponent,
CrmIndexComponent,
CrmSearchComponent,
CrmSearchResultComponent,
ReactiveFormsModule
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RoutingModule,
Select2Module,
[AlertModule.forRoot()]
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
答案 0 :(得分:8)
您需要将其添加到imports
,而不是declarations