【发布时间】:2016-12-23 19:43:19
【问题描述】:
如何在我的应用程序中使用 Ionic Storage。我尝试了以下内容,但是当我尝试读出时,我总是得到 [object Object] 作为值回来。当我在一个类中有 get/set 方法时它可以工作,但我想构建我的项目并将存储部分外包。
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
constructor(public testData: TestData) {}
onLogin(form) {
if (form.valid) {
this.testData.setTestParam("abc");
console.log("Stored: " + this.testData.getTestParam()) ;
// delivers => Stored: [object Object]
}
}
TestData 类
@Injectable()
export class TestData {
constructor(public storage : Storage) {}
setTestParam(testparam)
{
this.storage.set('test_param', testparam);
}
getTestParam(){
return this.storage.get('test_param').then((value) => {
return value;
});
}
}
【问题讨论】:
-
如果您使用的是 chrome,请转到您的调试控制台并进入您的应用程序选项卡,然后查看数据是如何保存在 WebSQL 或使用的任何驱动程序下的