我刚刚看到这个问题,但我仍然有同样的错误。我有一个共享模块,我将它导入到我的功能模块中。但我也尝试直接将模块导入我FormsModule
的ReactiveFormsModule
功能模块。
Angular 2.0 最终版。
我的共享模块是:
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { UPLOAD_DIRECTIVES } from 'ng2-uploader/ng2-uploader';
import { UploadComponent } from './upload/index';
import { AuthenticationService } from './services/index';
@NgModule({
declarations: [ UploadComponent, UPLOAD_DIRECTIVES ],
imports: [ CommonModule ],
providers: [ AuthenticationService ],
exports: [
FormsModule,
CommonModule,
UploadComponent,
ReactiveFormsModule
]
})
export class SharedModule { }
我的功能模块:
import { NgModule } from '@angular/core';
import { SharedModule } from '../shared/shared.module';
import { LoginComponent } from './login.component';
@NgModule({
imports: [ SharedModule ],
declarations: [ LoginComponent ],
exports: [ LoginComponent ]
})
export class LoginModule {
constructor() {}
}
组件:
import { Component } from '@angular/core';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
import { AuthenticationService } from '../shared';
@Component({
selector: 'pol-login',
templateUrl: 'login.component.html'
})
export class LoginComponent {
loginForm: FormGroup;
notValidCredentials: boolean = false;
showUsernameHint: boolean = false;
constructor(
fb: FormBuilder,
private authenticationService: AuthenticationService) {
this.loginForm = fb.group({
username: ['', Validators.compose([Validators.required, this.emailValidator])],
password: ['', Validators.required]
});
...
}
和观点:
<form class="container" (ngSubmit)="authenticate()" [ERROR ->][FormGroup]="loginForm">
....
</form>
所有路径和导入都是正确的。有任何想法吗?谢谢。
- - - [解决了] - - - -
更改[FormGroup]="loginForm"
为[formGroup]="loginForm"
:(