gpt4 book ai didi

javascript - Angular2 ReactiveFormsModule 意外的模块

转载 作者:搜寻专家 更新时间:2023-10-30 21:15:14 27 4
gpt4 key购买 nike

我一直在开发我的应用程序。我想使用 ReactiveFormsModule 模块,但我得到了

Error: Unexpected module 'ReactiveFormsModule' declared by the module 'AppModule'

我已将 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com