我一直在开发我的应用程序。
我想使用ReactiveFormsModule模块,但是我正在
我已经在我的项目中安装了angular / forms,但是似乎没有任何效果。
任何的想法?
我的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 {}
最佳答案
您需要将其添加到imports
而不是declarations
关于javascript - Angular2 ReactiveFormsModule意外模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45091606/