ios 当 ionic 2 页面完全加载时运行函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36533739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run function when an ionic 2 page has fully loaded
提问by Bill Noble
Is there a way to determine when an ionic 2 page has fully loaded? I need to insert some html into the page when all of the page html has been loaded. Ideally I would like to have a function in my @page class that runs when the page has been loaded.
有没有办法确定 ionic 2 页面何时完全加载?加载所有页面 html 后,我需要在页面中插入一些 html。理想情况下,我希望在我的 @page 类中有一个在页面加载时运行的函数。
At the moment I am inserting an iframe containing a vine into a div container. I am experiencing, when running the app on an iPhone 5 running iOS 9, some peculiar behaviour where the same vine sometimes sizes to the container and sometimes doesn't. I am guessing that this might be due to timing (the source for the vine iframe is received as part of an http request).
目前,我正在将一个包含藤蔓的 iframe 插入到 div 容器中。我遇到了,在运行 iOS 9 的 iPhone 5 上运行应用程序时,一些奇怪的行为,其中相同的藤蔓有时会调整到容器的大小,有时不会。我猜这可能是由于时间原因(藤 iframe 的源是作为 http 请求的一部分接收的)。
回答by artberri
You can use the ionViewDidLoad
method:
您可以使用以下ionViewDidLoad
方法:
@Page({
templateUrl: 'build/pages/somepage/somepage.html'
})
export class SomePage {
constructor() {
// ...
}
ionViewDidLoad() {
// Put here the code you want to execute
}
}
The lifecycle events as November 18, 2016 are:
截至 2016 年 11 月 18 日的生命周期事件是:
- ionViewDidLoad
- ionViewWillEnter
- ionViewDidEnter
- ionViewWillLeave
- ionViewDidLeave
- ionViewWillUnload
- ionViewCanEnter
- ionViewDidLoad
- ionViewWillEnter
- ionViewDidEnter
- 离子视图将离开
- ionViewDidLeave
- ionViewWillUnload
- ionViewCanEnter
Since Ionic 2 is in active development, things change all the time. If you would like to check the current lifecycle events, please refer to: https://ionicframework.com/docs/v2/api/navigation/NavController/#lifecycle-events
由于 Ionic 2 正在积极开发中,因此事情一直在变化。如果您想查看当前的生命周期事件,请参考:https: //ionicframework.com/docs/v2/api/navigation/NavController/#lifecycle-events
回答by Günter Z?chbauer
You can use the lifecycle callback ngAfterViewInit()of the component that is loaded last (depends on your routing).
您可以使用最后加载的组件的生命周期回调ngAfterViewInit()(取决于您的路由)。