我在弄乱角度时遇到此错误。我曾尝试研究此问题,但是我遇到的大多数解决方案都是导入FormsModule,ReactiveFormsModule,但是我的方法不起作用。
Uncaught (in promise): Error: Template parse errors:
Can't bind to 'formGroup' since it isn't a known property of 'form'. ("
<ion-content padding>
<form [ERROR ->][formGroup]="signupForm">
<ion-item>
<ion-label position="stacked">Email</ion-label>
"): ng:///SignupPageModule/SignupPage.html@12:8
No provider for ControlContainer
我在app.module.ts中尝试了FormsModule,ReactiveFormsModule的导入。而且不起作用。
这是我的app.module.ts文件
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
FormsModule,
ReactiveFormsModule
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
这是我的HTML文件:
<form [formGroup]="loginForm">
<ion-item>
<ion-label position="stacked">Email</ion-label>
<ion-input
formControlName="email"
type="email"
placeholder="Your email address"
[class.invalid]="!loginForm.controls['email'].valid &&
loginForm.controls['email'].touched"
>
</ion-input>
</ion-item>
<ion-item
class="error-message"
*ngIf="!loginForm.controls['email'].valid &&
loginForm.controls['email'].touched"
>
<ion-label>Please enter a valid email address.</ion-label>
</ion-item>
<ion-item>
<ion-label position="stacked">Password</ion-label>
<ion-input
formControlName="password"
type="password"
placeholder="Your password"
[class.invalid]="!loginForm.controls['password'].valid&& loginForm.controls['password'].touched"
>
</ion-input>
</ion-item>
<ion-item
class="error-message"
*ngIf="!loginForm.controls['password'].valid
&& loginForm.controls['password'].touched"
>
<ion-label>Your password needs more than 6 characters.</ion-label>
</ion-item>
<ion-button (click)="loginUser(loginForm)" expand="block" [disabled]="!loginForm.valid">
Log In
</ion-button>
</form>
<ion-button expand="block" fill="clear" routerLink="/signup">
Create a new account
</ion-button>
<ion-button expand="block" fill="clear" routerLink="/reset-password">
I forgot my password
</ion-button>