简体   繁体   English

错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改

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

I was getting an object that contained an array of objects by making an HTTP call in my angular app.通过在我的角度应用程序中进行 HTTP 调用,我得到了一个包含对象数组的对象。 I want to display them via this HTML:我想通过这个 HTML 显示它们:

          <div class="row text-white">
            <div class="col-6">
              <h4 class="pt-1 m-0 text-white">
                <ng-container *ngIf="optionsForVideoPostGraph && optionsForVideoPostGraph.series">
                  <i style="font-size: 2vw;" class="fa fa-male"></i>
                  <span>{{ optionsForVideoPostGraph?.series[0]?.data.pop() }}</span>
                  <br> Total Male user <br>
                  <i style="font-size: 2vw;" class="fa fa-female"></i>
                  <span>{{ optionsForVideoPostGraph?.series[1]?.data.pop() }}</span>
                </ng-container>
              </h4>
            </div>
            <div class="col-6 text-right pl-0">
              <span>{{ optionsForVideoPostGraph?.series[2]?.data.pop() }}</span>
              <br />
              <span>Total</span>
            </div>
          </div>

The variable optionsForVideoPostGraph looks like: [变量optionsForVideoPostGraph看起来像:[回复1

The HTTP call was done inside the ngOnit lifecycle hook. HTTP 调用是在 ngOnit 生命周期挂钩中完成的。 What have I done wrong here?我在这里做错了什么?

You're getting that error because you are calling pop() within your template, since pop() removes the last element from the array.您收到该错误是因为您在模板中调用pop() ,因为pop()从数组中删除了最后一个元素。 You'll need to access the last element in a different way.您需要以不同的方式访问最后一个元素。

The simplest way to do this is probably:最简单的方法可能是:

{{ optionsForVideoPostGraph?.series[0]?.data[optionsForVideoPostGraph.series[0].data.length] }}

暂无
暂无

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

相关问题 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:检查后表达式已更改 - Uncaught 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