角度2(Ionic 2)在页面显示时调用页面中的功能 [英] Angular 2 (Ionic 2) call a function in a page when ever page is displayed
问题描述
当我的主页在 角色2(离子2)
应用程序加载时,我想要呼叫服务/功能。如何实现这一点?
When ever my home page in angular 2(ionic 2)
app is loaded I want call service/function. How to achieve this?
首次加载应用程序(主页加载)时,我可以在 构造函数
,但是当用户开始使用该应用程序并且 将
新页面 导航控制器
和 pop
返回到 主页
, 构造函数
不会再调用。
For the first time when the app is loaded(home page is loaded) I can write this in the constructor
, but when user start using the app and push
new pages into nav controller
and pop
them to come back to home page
, the constructor
wont get called again.
我想知道实现此功能的最佳方式是什么?
I would like to know what is the best way to achieve this feature?
我是新的 angular2
和 ion2
框架
(也没有 角度1
和 ion1
),请帮助我。
I am new to angular2
and ionic2
framework
(also don't have experiences in angular1
and ionic1
), please help me out.
很多谢谢。
import {Page, NavController, Platform, Storage, SqlStorage} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/page1/page1.html'
})
export class Page1 {
static get parameters(){
return [[NavController],[Platform]];
}
ngOnInit() {
console.log("Showing the first page!");
}
constructor(nav, platform){
this.nav = nav;
this.platform = platform;
}
}
推荐答案
strong> onPageWillEnter()
为我工作。
onPageWillEnter()
worked for me.
import {Page, NavController, Platform, Storage, SqlStorage} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/page1/page1.html'
})
export class Page1 {
static get parameters(){
return [[NavController],[Platform]];
}
onPageWillEnter() {
console.log("Showing the first page!");
}
constructor(nav, platform){
this.nav = nav;
this.platform = platform;
}
}
这篇关于角度2(Ionic 2)在页面显示时调用页面中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!