【发布时间】:2019-02-28 23:20:58
【问题描述】:
当我使用platform.exitApp() 时,对localStorage 的更改在执行退出之前所做的更改没有保存。
这是我的启动方式:
this.user.profileGetbyId(this.user.userdata.id)
.subscribe(res => {
if(res && res.success) {
localStorage.setItem('user', res.data);
this.user.userdata = res.data;
console.log(this.user.userdata);
this.platform.exitApp();
//temp decision
// setTimeout(() => {
// this.platform.exitApp();
// }, 500);
}
})
这样,在exit() 启动之前,控制台显示我已经更新了用户,但是当我下次启动应用程序时,我拥有exit() 之前的用户。
我尝试的下一件事是使用setTimeout() 延迟调用exit。有了这个timeout,用户可以正确保存。
如果没有setTimeout(),我如何以正确的方式保持更改?
【问题讨论】:
标签: javascript angular typescript ionic-framework ionic2