我想将表单验证实施到我的Ionic表单中。但它总是给我一个错误,即formGroup不是form的属性。
我已经将模块导入了app.modules.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
IonicStorageModule.forRoot(),
ReactiveFormsModule,
FormsModule,
HttpModule
],
和我的landing-page.ts
import { Validators, FormBuilder, FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';
在这里创建验证器
export class LandingPage implements OnInit {
public formUserSetup: FormGroup;
constructor(
private menu: MenuController,
public formBuilder: FormBuilder
) {
this.menu.enable(false);
this.formUserSetup = formBuilder.group({
firstname : new FormControl('', Validators.compose([Validators.required])),
lastname : new FormControl('', Validators.compose([Validators.required])),
email: new FormControl('', Validators.compose([Validators.required]))
});
}
ngOnInit() {
}
}
表单本身:
<form [formGroup]="formUserSetup">
<ion-input type='text' formControlName="firstname"></ion-input>
</form>