首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于ngOnInit上的http调用,ionic 4页面转换挂起

由于ngOnInit上的http调用,ionic 4页面转换挂起
EN

Stack Overflow用户
提问于 2019-06-13 07:24:54
回答 1查看 483关注 0票数 1

我正在用ionic 4构建一个应用程序。当从一个页面导航到另一个页面时,它并不是很流利。

我正在使用routerLink="/make-order/{{item.name}}" routerDirection="forward"转到下一页。在这个(下一个)页面的ngOnInit函数中,我执行了一些http调用来获取数据。问题是,这会对页面过渡产生影响。它不流畅,它挂起,直到数据加载。我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 15:04:28

我有两个解决办法:第一,你可以把初始化代码移到一个不同的(稍后的) Angular生命周期钩子中。https://angular.io/guide/lifecycle-hooks#lifecycle-examples

可能是AfterViewAfterContent,或者使用Ionic的钩子:ionViewWillEnterionViewDidEnterionViewWillLeaveionViewDidLeave

第二,你可以使用延时运算符向可观测对象添加一个延时。https://www.learnrxjs.io/operators/utility/delay.html

这应该允许在发出请求之前完成转换。

进一步的研究:

我在离子文档里找到了这个

代码语言:javascript
复制
Lifecycle Events
With V4, we're now able to utilize the typical events provided by Angular. But for certain cases, you might want to have access to the events fired when a component has finished animating during it's route change. In this case, the ionViewWillEnter, ionViewDidEnter, ionViewWillLeave, and ionViewDidLeave have been ported over from V3. Use these events to coordinate actions with Ionic's own animations system.

Older events like ionViewDidLoad, ionViewCanLeave, and ionViewCanEnter have been removed, and the proper Angular alternatives should be used.

For more details, checkout the router-outlet docs

https://beta.ionicframework.com/docs/building/migration#lifecycle-events

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56571539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档