[英]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
看起来像:[
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.