错误:ExpressionChangedAfterItHasBeenCheckedError:上一个值:ng-untouched:true.当前值:"ng-untouched:false" [英] Error: ExpressionChangedAfterItHasBeenCheckedError: Previous value: 'ng-untouched: true'. Current value: 'ng-untouched: false'

查看:125
本文介绍了错误:ExpressionChangedAfterItHasBeenCheckedError:上一个值:ng-untouched:true.当前值:"ng-untouched:false"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用最少的代码在 StackBlitz 上重现了该问题.

I have reproduced the issue on StackBlitz with minimal code.

第1步:点击文字

第2步:关注文本字段

第3步:输入enter并检查控制台中的错误

Step 3: Type enter and check the console for this error

错误:ExpressionChangedAfterItHasBeenCheckedError:表达式具有检查后更改.上一个值:'ng-untouched:true'.当前值:"ng-untouched:false".

Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ng-untouched: true'. Current value: 'ng-untouched: false'.

推荐答案

您必须使用 ChangeDetectorRef detectChanges()方法在指令中手动触发更改检测.

You have to manually trigger change detection in the directive using the detectChanges() method of the ChangeDetectorRef

像这样修改 editable-on-enter-inplace.directive.ts :

从"@ angular/core"导入{Directive,HostListener,ChangeDetectorRef};

 constructor(private editable: EditableInplaceComponent,private cdr: ChangeDetectorRef) { }

  @HostListener('keyup.enter')
  onEnter() {
    this.editable.toViewMode();
    this.cdr.detectChanges();
  }

这篇关于错误:ExpressionChangedAfterItHasBeenCheckedError:上一个值:ng-untouched:true.当前值:"ng-untouched:false"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆