Ionic 2 / Angular 2 个组件生命周期钩子

Ionic 2 / Angular 2 component lifecycle hooks

我在页面中有一个组件,每次导航到该页面时我都需要连接到该组件。它包含一个 mapbox 地图,我发现如果用户使用注册页面注册并拉起键盘然后返回地图页面,地图 div 较小,因为用户拉开phone 上的键盘。我希望这是有道理的?

我已经尝试了此处列出的所有挂钩 https://angular.io/guide/lifecycle-hooks,但是每次导航到该页面时都会触发 none 个挂钩。

任何帮助都会很棒。

尝试:ionViewDidEnter(),连同 @ViewChild。使用 @ViewChild 您可以访问该组件。

来自离子 docs:
ionViewDidEnter() 将在页面完全进入且现在是活动页面时触发。无论是第一次加载还是缓存页面,都会触发此事件。”

这样您就可以在每次导航到该页面时调用组件上的函数。

父页 TS:

@Component({
    selector: 'parent-page',
    templateURL: 'parent-page.html'
})
export class ParentPage{
    @ViewChild('myComponent') myComponent;

    constructor(){}

    ionViewDidEnter(){
        this.myComponent.someFunc();
    }

    ...
}

父页面HTML:

<ion-content>
    ...
    <child-component #myComponent></child-component>
    ...
</ion-content>