2017-08-10 30 views
-1

當我嘗試啓動我的角應用程序在本地我有第四個錯誤「錯誤FormBuilder不是NgModule」,我試過我可以做的一切,npm安裝,檢查我的包json ,可以解決我的問題的所有事情,你能幫助我,還是你有任何解決方案?錯誤FormBuilder是不是一個NgModule時,生成

這是我的組件:

import { Component } from '@angular/core'; 
import { FormGroup, Validators, NgForm, FormBuilder } from '@angular/forms'; 
import { Router } from '@angular/router'; 

import { AuthentificationService } from './authentification.service'; 


@Component({ 
    selector: 'app-authentification', 
    templateUrl: './authentification.component.html', 
    styleUrls: ['./authentification.component.css'] 
}) 
export class AuthentificationComponent { 



    loginForm: FormGroup; 
    error: string = ''; 

    constructor(
    private formBuilder: FormBuilder, 
    private authentificationService: AuthentificationService, 
    private router: Router 
) { 
    this.loginForm = formBuilder.group({ 
     'oxylaneId': ['', Validators.required], 
     'password': ['', Validators.required] 
    }); 
    } 
    onSubmit() { 
    this.authentificationService 
     .authenticate(this.loginForm.value) 
     .subscribe(
     data => { 
      localStorage.setItem('id_token', data.token); 
      this.router.navigate(['email']); 
     }, 
     error => this.error = error.message 
    ); 
    } 


    loginUser(form: NgForm) { 
    console.log(form.value); 
    } 
    onChange(deviceValue) { 
    console.log(deviceValue); 
    } 



} 

而且我用我所有的模塊和組件

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 

import { AppComponent } from './app.component'; 
import { FormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms'; 
import { EmailcomponentComponent } from './emailcomponent/emailcomponent.component'; 
import { ColorcomponentComponent } from './colorcomponent/colorcomponent.component'; 
import { DesigncomponentComponent } from './designcomponent/designcomponent.component'; 
import { AppRoutingModule }  from './app-routing.module'; 
import { TopBarComponent } from './top-bar/top-bar.component'; 
import { AuthentificationComponent } from './authentification/authentification.component'; 

@NgModule({ 

    imports: [ 
    BrowserModule, 
    FormsModule, 
    AppRoutingModule, 
    FormBuilder, 
    FormGroup, 
    Validators, 

    ], 
    declarations: [ 
    AppComponent, 
    EmailcomponentComponent, 
    ColorcomponentComponent, 
    DesigncomponentComponent, 
    TopBarComponent, 
    AuthentificationComponent, 
    ], 

    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

回答

0

app.module的錯誤說: 「FormBulder不是NgModule」 和它的不!您應該既不導入FormBuilder也不導入FormGroupValidators也不屬於Imports,除非它是您的特徵模塊。進口FormsModuleReactiveFormsModule代替,例如:

imports: [ 
    BrowserModule, 
    FormsModule, 
    ReactiveFormsModule 
    AppRoutingModule 
] 

編輯:

最佳做法是,從來沒有進口FormsModuleReactiveFormsModule,無論是一個或另一個!

+0

非常感謝這個迴應,它的工作:) –

+0

很高興幫助。不要忘記標記爲答案 – DAG

相關問題