Ionic 4 重置表单后提交重定向回传错误不清除。

问题描述 投票:1回答:1

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();
    }
angular ionic-framework ionic4 angular-forms
1个回答
0
投票

这样就可以了

@ViewChild('loginForm', {static:false}) slForm: NgForm;

onLogin(form: NgForm) {
    this.submitted = true;
    this.slForm.reset();
}
© www.soinside.com 2019 - 2024. All rights reserved.