问题
In my Ionic 3 Angular app there is a component I wrote which is using chart.js charts.
These charts are injected using . The problem is when the app is rendered the component is sometimes not yet initialized and the chart data initialization throws undefined errors.
On Ionic page the method ionicViewDid load gets invoked. But in component it seems the same method doesn't get called.
So what is the best way to do data initialization by knowing that canvas got initialized.
回答1:
You can try ngOnInit hook, and ngAfterViewInit.
ngOnInit will be called after data-bound properties of a directive are initialized.
AfterViewInit will be called after a component's view has been fully initialized.
class Some implements OnInit, AfterViewInit {
ngOnInit() {
}
ngAfterViewInit() {}
}
来源:https://stackoverflow.com/questions/46332196/ionic-3-angular-component-load-listener