Ionic2 Angular2 - 在ionic2中更改页面之前有没有办法解决promises

时间:2016-08-07 12:24:15

标签: angular ionic2

我在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=>{
     ...
   });
  }

}

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

有什么线索我能做到这一点吗?

1 个答案:

答案 0 :(得分:1)

Ionic应用程序中的页面会发生一些页面加载生命周期事件。您可以查看并查看@ionViewWillEnter@ionViewCanEnter是否适合您。

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