ionic-team / ionic-team/ionic-docs
How to run code when a component or page is loaded
- 主要语言
- MDX
- 星标
- 621
- 派生
- 3.2k
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 86
描述
_Original issue by @ari62 on [2021-04-12T23:59:47Z](https://github.com/ionic-team/ionic-framework/issues/23184)_
# Documentation
Using ionic navigation and ngOnInit won't get fired, as described here :
https://ionicframework.com/docs/angular/lifecycle
However when refreshing the page (browser reload) ionViewDidEnter/ionViewWillEnter don't get fired for components but they seem to be getting fired for Pages along with ngOnInit.
The documentation says
"ngOnInit - Initialize your component and load data from services that don't need refreshing on each subsequent visit."
However why wouldn't someone want their data refreshed on a browser reload for components? This leads us to putting the same code in ngOnInit and ionViewWillEnter, which gets called twice for pages on refresh.
There should be a single place where code can be put to take care of both refreshes and navigation without having to worry about it getting called twice or not at all, or the documentation should be improved to specify how to remove ionic based navigation.
贡献指南
调研方向
Start with the Angular lifecycle documentation linked in the issue and review the behavior described for ion-router-outlet, ngOnInit, ionViewDidEnter, and ionViewWillEnter. Clarify how browser reloads and navigation affect components versus pages, then update the documentation so the recommended single place for loading data and avoiding duplicate calls is explicit.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100