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

发布于 2019-06-13 15:04:28
我有两个解决办法:第一,你可以把初始化代码移到一个不同的(稍后的) Angular生命周期钩子中。https://angular.io/guide/lifecycle-hooks#lifecycle-examples
可能是AfterView或AfterContent,或者使用Ionic的钩子:ionViewWillEnter、ionViewDidEnter、ionViewWillLeave和ionViewDidLeave
第二,你可以使用延时运算符向可观测对象添加一个延时。https://www.learnrxjs.io/operators/utility/delay.html
这应该允许在发出请求之前完成转换。
进一步的研究:
我在离子文档里找到了这个
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 docshttps://beta.ionicframework.com/docs/building/migration#lifecycle-events
https://stackoverflow.com/questions/56571539
复制相似问题