简体   繁体   English

未捕获的错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改

[英]Uncaught Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked

Uncaught Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.未捕获的错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改。 Previous value: 'ngIf: false'.以前的值:'ngIf:false'。 Current value: 'ngIf:当前值:'ngIf:

I have been trying to get updated value on clicking button after going to several sub pages with in the same component, YES and NO value does not update(Only on the current page it works), though I can see it through console log in my method.在转到同一组件中的几个子页面后,我一直试图在单击按钮时获取更新的值, YESNO值不会更新(仅在当前页面上有效),尽管我可以通过控制台日志看到它方法。 Below is my code.下面是我的代码。 and I tried below URL我试过下面的网址

ngIf - Expression has changed after it was checked ngIf - 检查后表达式已更改

  constructor(
  ) {

  }
 getAssessBtn1(value: any) {    
    this.assesseeValidation = false;
    if (value == 'Yes') {
      this.showAssessBtn1 = true;
      this.showAssessCondition1 = false;
    } else {
      this.showAssessBtn1 = false;
    }
  } 

I was trying with ngAfterViewChecked, how can I use the method getAssessBtn1(value: any) inside it.我正在尝试使用 ngAfterViewChecked,如何在其中使用getAssessBtn1(value: any)方法。

HTML : HTML :

<button data-auto-id="AdultTravellersAssess" *ngIf="showAssessBtn1 
                          class="btn btn-secondary assess-btn custom-theme-group-two"
                          (click)="test()">
                    Access
              

You can use ChangeDetectionRef for triggering change detection event right after changing the showAssessBtn or showAssesCondition1 .您可以使用ChangeDetectionRef改变后触发变化检测事件右showAssessBtnshowAssesCondition1

// inject the changeDetectionRef into your component with
constructor(private cd: ChangeDetectionRef) {}


// in the getAssessBtn1 method trigger change detection
getAssessBtn1(value: any) {
 this.assesseeValidation = false;
 if (value == 'Yes') {
   this.showAssessBtn1 = true;
   this.showAssessCondition1 = false;
 } else {
   this.showAssessBtn1 = false;
 }
 this.cd.detectChanges();
}

With this approach, angular will not complain about expression changed after value is checked.使用这种方法,angular 不会抱怨检查值后表达式更改。 Because you are re-triggering the change detection event when you set your expression to another value.因为当您将表达式设置为另一个值时,您正在重新触发更改检测事件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改 - Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked ERROR 错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改 - ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked Angular:错误错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改 - Angular: ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked 错误设置宽度 - 错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改 - Error setting width - Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked ERROR 错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。 Angular - ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Angular 面临错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改 - Facing Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked Angular7 + REDUX:错误:“ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改 - Angular7 + REDUX: Error: "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked 自定义图例时出现错误“ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked” - Getting Error “ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked” on customizing legends Angular 中的“ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改”错误 - "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked" error in Angular 计算得到错误的值:ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked - calcuate value getting the error : ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM