你好,我想从诺言分配返回值到外部变量。 我尝试了很多次,但最后我放弃了。离子存储和变量
export class TestPage {
test:any;
constructor(private storage: Storage) {
storage.get('testy').then((value) => {
this.test = value;
});
}
}
你好,我想从诺言分配返回值到外部变量。 我尝试了很多次,但最后我放弃了。离子存储和变量
export class TestPage {
test:any;
constructor(private storage: Storage) {
storage.get('testy').then((value) => {
this.test = value;
});
}
}
尽量给构造函数外的存储和查询
export class TestPage {
test:any;
constructor(private storage: Storage) {}
this.storage.get('testy').then((value) => {
console.log('Testvalue is', value);
this.test = value;
});
}
尝试获得访问使用ionViewWillEnter事件加载页面之前的存储空间值:
export class TestPage {
test:any;
constructor(private storage: Storage) {}
ionViewWillEnter(){
this.storage.get('testy').then((value) => {
console.log('Testvalue is', value);
this.test = value;
});
}
}
仍然我得到未定义的错误:/ – Divers
你怎么知道你失败了?你在哪里显示/使用'this.test'? – echonax
它显示undefined,如果我把外面。然后 – Divers
检查你试图存储值的地方 –