[英]How to load data in constructor, and render it via Chartjs in ngAfterViewInit?
Here's my problem. 这是我的问题。 A lot of examples of using Chartjs in Angular only assume that data is already there , and they render it in
ngAfterViewInit
. 在Angular中使用Chartjs的许多示例仅假设数据已经存在 ,并在
ngAfterViewInit
渲染。
However, I can't figure out how to meet my requirements: 但是,我不知道如何满足我的要求:
mat-spinner
mat-spinner
document.getElementById('canvasId')
, since it's not rendered yet. document.getElementById('canvasId')
空引用,因为它尚未呈现。 ngAfterViewInit
, then I don't know when data is loaded, since it's indeterminate, and I encounter null reference for the properties of my data object. ngAfterViewInit
加载数据并想在ngAfterViewInit
渲染画布,那么我不知道何时加载数据,因为它是不确定的,并且我遇到的数据对象属性为null。 ngAfterViewInit
, then Angular complains that ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: undefined'. Current value: 'ngIf: true'
ngAfterViewInit
加载数据,则Angular会抱怨ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: undefined'. Current value: 'ngIf: true'
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: undefined'. Current value: 'ngIf: true'
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: undefined'. Current value: 'ngIf: true'
. ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: undefined'. Current value: 'ngIf: true'
。 This error is related to mat-spinner *ngIf='progress'
mat-spinner *ngIf='progress'
I'm stuck at this point on how to reconcile these requirements. 我现在停留在如何调和这些要求上。 Any help?
有什么帮助吗?
This post uses a service to get data and render the chart after the data is loaded. 这篇文章使用服务来获取数据并在加载数据后呈现图表。 Hope it helps!
希望能帮助到你!
Angular Load Data from Service 来自服务的角负载数据
I was getting the expression changed error but loading and executing in OnInit worked for me. 我遇到表达式更改错误,但是在OnInit中加载和执行对我来说很有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.