2017-06-20 64 views
0

有没有什么方法可以在我进入特定页面时调用特定功能? 就像我想在一个div标签的页面末尾调用一个函数,所以当用户打开该页面时,div也会触发该函数。Ionic 2,Angular 2;在启动时调用特定功能

+0

参阅有关[2离子生命周期钩(https://ionicframework.com/docs/api/navigation/NavController/) – Duannx

+0

感谢您的回复,但我想显示上的特定位置该功能。我也尝试过钩子 –

+0

我仍然认为@Duannx离子2生命周期钩将是你最好的地方。并使用'ionViewDidEnter'函数您需要在页面加载运行 –

回答

0

下面是解决方案使用它,它会帮助你。

// Annotation section 
@Component({ 
    selector: 'street-map', 
    template: '<map-window></map-window><map-controls></map-controls>', 
}) 
// Component controller 
class StreetMap { 
    ngOnInit() { //here you can call the function wanted 
    // Properties are resolved and things like 
    // this.mapWindow and this.mapControls 
    // had a chance to resolve from the 
    // two child components <map-window> and <map-controls> 
    } 
} 

这里是更多细节。 http://learnangular2.com/lifecycle/

相关问题