Ionic 3 Angular组件负载侦听器 [英] Ionic 3 Angular component load listener

查看:73
本文介绍了Ionic 3 Angular组件负载侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Ionic 3 Angular应用中,我编写了一个使用chart.js图表​​的组件。

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.

在Ionic页面上,调用ionicViewDid加载方法。但是在组件中,似乎没有调用相同的方法。

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.

推荐答案

您可以尝试 ngOnInit 钩子和 ngAfterViewInit

ngOnInit。

在组件的视图完全被使用之后,将调用AfterViewInit

AfterViewInit will be called after a component's view has been fully initialized.

class Some implements OnInit, AfterViewInit {
  ngOnInit() {
  }
  ngAfterViewInit() {}
}

这篇关于Ionic 3 Angular组件负载侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆