情况:
原文链接:https://www.f2er.com/angularjs/240467.html我想在我的Ionic 2应用程序中创建一个非常简单的登录表单.
无论我尝试什么,我都会收到这个错误:
formGroup expects a FormGroup instance. Please pass one in.
代码:
页面组件:
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { FormGroup,Validators,FormBuilder } from '@angular/forms'; @Component({ selector: 'login-page',templateUrl: 'login-page.html' }) export class LoginPage { loginForm: FormGroup; constructor(public navCtrl: NavController,private formBuilder: FormBuilder) {} ionViewDidLoad() { console.log('Login page loaded'); this.loginForm = this.formBuilder.group({ email: ['',Validators.required],password: ['',}); } submitLogin() { console.log('Doing login..'); } }
风景:
<ion-header> <ion-navbar> <ion-title>LoginPage</ion-title> </ion-navbar> </ion-header> <ion-content padding> <form [formGroup]="loginForm" (ngSubmit)="submitLogin()"> <ion-item> <ion-label>Email</ion-label> <ion-input #email type="email" formControlName="email"></ion-input> </ion-item> <ion-item> <ion-label>Password</ion-label> <ion-input #password type="text" formControlName="password"></ion-input> </ion-item> <button ion-button block type="submit">Submit</button> </form> </ion-content>
问题:
你为什么我得到错误?
你知道那段代码有什么问题吗?
谢谢!