3

I have been working on my app. I want to use ReactiveFormsModule module but I am getting

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

I have installed angular/forms into my project but nothing seems to work. Any idea?

My component.ts file

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());
  }
}

My 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 {}

1 Answer 1

13

You need to add it to your imports, rather than your declarations

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.