【问题标题】:Ionic2 Angular2 - Is there any way to resolve promises before changing page in ionic2Ionic2 Angular2 - 在 ionic2 中更改页面之前有什么方法可以解决承诺
【发布时间】:2016-08-07 12:24:15
【问题描述】:

我将某些信息存储在 SqlStorage 中。当我尝试检索该信息时,我得到了一个承诺:

export class ProfileService {
  this.storage = new Storage(sqlStorage);

  get fname() {
    this.storage.get('fname');
  }
  ...
  ..

}

现在在显示用户个人资料时,我需要显示来自个人资料服务的信息:

@Page({
  ...
})
export class DisplayProfile {
  fname: AbstractControl;

  constructor(private _profile: ProfileService) {

     // SEE HERE
     this._profile.get('fname').then(value => {
       this.fname.value = value;
    });

    this._profile.get('lname').then(value=>{
     ...
   });
  }

}

正如您在上面看到的,我正在解决页面构造器中的承诺。 我宁愿在页面加载之前解决这些承诺(就像 Angular1 状态更改中的解析块一样)。

有什么办法可以做到这一点吗?

【问题讨论】:

    标签: angular ionic2


    【解决方案1】:

    Ionic 应用中的页面会发生几个页面加载生命周期事件。你可以看看@ionViewWillEnter@ionViewCanEnter 是否适合你。

    可以在此处找到这些生命周期的完整列表以及如何使用它们的说明:Ionic Lifecycle

    【讨论】:

      猜你喜欢
      • 2017-09-07
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多