首页 > 解决方案 > 获取错误“检查后表达式已更改”禁用离子项

问题描述

我在 Ionic 2 中有一个小表单,ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.当我尝试禁用输入时出现错误。

这是我的代码:

.html

<ion-card-content [formGroup]="mfaForm">    
   <ion-input formControlName="otpValue" (keyup)="onOtpChange()" type="number"></ion-input>
</ion-card-content>

.ts

ngOnInit() {
   this.buildForm();
}

onOtpChange(): void {
   const otpValue: string = this.mfaForm.get('otpValue').value;
   if (otpValue.length === OTP_CODE_MAX_LENGTH) {
      this.mfaForm.get('otpValue').disable();
   }
}

private buildForm(): void {
   this.mfaForm = this.formBuilder.group({
     otpValue: ['']
   });
}

有人知道为什么会这样吗?

标签: angularmobileionic3

解决方案


推荐阅读