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

时间:2017-07-30 21:58:14

标签: angular events ionic2 hook lifecycle

我在页面中有一个组件,每次导航到页面时都需要挂钩。它包含一个mapbox地图,我发现它没有正确调整大小如果用户注册使用注册页面并拉起键盘然后返回到地图页面地图div较小,因为用户拉开了他们的键盘电话。我希望这有道理吗?

我已经尝试了https://angular.io/guide/lifecycle-hooks中列出的所有钩子,但每次导航到页面时都不会触发。

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:5)

尝试: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>
相关问题