angular - Ionic 2/Angular 2 组件生命周期钩子(Hook)

标签 angular events ionic2 hook lifecycle

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

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

任何帮助都会很棒。

最佳答案

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

来自 Ionic 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>

关于angular - Ionic 2/Angular 2 组件生命周期钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45405101/

相关文章:

javascript - rxjs - 理解 observable 和 observer

javascript - 如何将事件监听器附加到打开的颜色框?

javascript - Onclick 文本出现在 div 旁边,而不是在下面

WPF:如何将鼠标事件附加到 View 模型?

angular - ionic : Item with title and detail text

javascript - ionic 2 : use NavController

Angular 日期格式更改日期

node.js - 在 Ubuntu 20 ec2 实例中设置 Ionic 环境时出错

javascript - Ionic 2 构建开发失败 : Maximum call stack size exceeded

javascript - 为 Angular 2 中的路由通用组件提供异步依赖关系。路由的解析等效项