【发布时间】:2017-02-08 20:59:59
【问题描述】:
我正在熟悉 Angular2、Ionic2 和 也许我误解了什么,但希望得到帮助。
我有一个名为“CurrentUser”的提供程序,用于存储和获取 LocalStorage 数据。
getProfile(): any {
this.local.get("user-profile").then((profile) => {
var val = JSON.parse(profile);
return val;
});
}
这个函数getProfile()返回一个承诺
如果我将此提供程序注入到组件中。从组件调用此函数时,在分配数据之前,我将如何等待解决的承诺?
@Component({
templateUrl: 'build/pages/book_meeting/book_meeting.html'
})
export class BookMeetingPage implements OnInit {
constructor(public navCtrl: NavController, private _currentUser: CurrentUser) {
}
profile: IProfile;
ngOnInit(): any {
this.profile = this._currentUser.getProfile();
console.log(this.profile);//returns undefined
}
}
【问题讨论】:
标签: angular typescript promise ionic2