Ionic 3 Angular component load listener

守給你的承諾、 提交于 2019-12-11 07:56:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!