【问题标题】:Angular2 ReactiveFormsModule Unexpected moduleAngular2 ReactiveFormsModule 意外的模块
【发布时间】:2017-07-13 21:59:40
【问题描述】:

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

错误:模块“AppModule”声明的意外模块“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 {}

【问题讨论】:

    标签: javascript angular typescript import


    【解决方案1】:

    您需要将其添加到您的imports,而不是您的declarations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 2017-09-08
      • 1970-01-01
      • 2015-10-08
      相关资源
      最近更新 更多