在提交重定向首页并返回注销后返回登录页面输入值后,Ionic 4重置表格被重置,但错误未清除错误,其显示*需要密码
<form #loginForm="ngForm" novalidate >
<ion-list>
<ion-item class="inputDesign">
<ion-input pattern="^(0|[1-9][0-9]*)$" placeholder="Password" maxlength="6" max="6" min="6" [(ngModel)]="loginForm.password" name="password" type="tel" minlength="6"
#password="ngModel" required></ion-input>
</ion-item>
<ion-text class="errorText" color="danger" *ngIf="password.errors && submitted == true">
<p [hidden]="!password.errors.required">*Password is required</p>
<p [hidden]="!password.errors.minlength">*Must be at least 6 characters long</p>
<p [hidden]="!password.errors.pattern">*Enter only number</p>
</ion-text>
</ion-list>
</form>
<ion-footer text-center >
<ion-toolbar color="secondary" (click)="onLogin(loginForm)" text-center type="submit">
<ion-title text-center>Login</ion-title>
</ion-toolbar>
</ion-footer>
ts文件
@ViewChild('loginForm') slForm: NgForm;
onLogin(form: NgForm) {
this.submitted = true;
this.slForm.reset();
}
答案 0 :(得分:0)
这很好
@ViewChild('loginForm', {static:false}) slForm: NgForm;
onLogin(form: NgForm) {
this.submitted = true;
this.slForm.reset();
}
答案 1 :(得分:0)
我有同样的问题。这终于对我有用:
this.form.reset();
Object.keys(this.form.controls).forEach(key => {
this.form.get(key).setErrors(null) ;
});