【问题标题】:Lifecycle hooks in safari mobile and ios app don’t worksafari mobile 和 ios 应用程序中的生命周期挂钩不起作用
【发布时间】:2020-11-18 18:10:00
【问题描述】:

生命周期挂钩在 Safari 移动或 ios 应用程序中均不起作用。

NgOnInit 和 ionViewDidLoad 以及任何其他生命周期钩子,它们都适用于桌面和 android 应用程序,但不适用于 ios 端。即使是第一次访问该页面。

但是,如果我点击/单击屏幕上的任意位置,那么一切都会完全按照需要加载。

另外,如果我再次导航到该页面或重新加载该页面,一切都如我所愿。

有什么建议吗?我没有收到任何错误。

我正在从 back4apps 的数据库中获取一些信息,并试图在页面打开时显示它。

打字稿

  ngOnInit() {
  this.unhide();
  }

unhide() {
this.news.get("deEygHXCR9").then((gameScore) => {
    this.memberList = gameScore.get("announcements");
  }, (error) => {
  });
}

html

<ion-item class = "backColor2">
      <ion-textarea class="textAreaHeight" readonly="true" auto-grow="true" type="text" name="memberList" [(ngModel)]="memberList" ></ion-textarea>
      </ion-item>

就像我说的,android 和 chrome 都可以正常工作。有关修复或替代方法的任何建议?我正在使用 ionic 5 和 angular 8

【问题讨论】:

    标签: angular typescript ionic5


    【解决方案1】:

    我不是最有经验的程序员……但我最终发现了问题……不是生命周期挂钩。这是因为我正在显示来自第三方的数据,并且为了让我的屏幕在检索数据后使用 ngmodel 更新它,我必须在 NgZone 内运行它……就像这样……

    import {  NgZone } from '@angular/core';
    
    
    constructor(
    public ngZone: NgZone,
      ) {}
    
    
    
    async unhide() {
    this.news.get("deEygHXCR9").then((gameScore) => {
    this.ngZone.run(() => {
        this.memberList = gameScore.get("announcements");
    });
      }, (error) => {
      });
    }
    

    感谢所有观看的人!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2020-12-27
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      相关资源
      最近更新 更多