Corin
June 15, 2016, 11:28pm
1
Hi Guys,
I am trying to use SqlStorage to set some values, but for some reason after set a value, when I try to get the value again is always empty.
let storage = new Storage(SqlStorage);
storage.set('name', 'Max');
storage.get('name').then((name) => {
console.log(name); // is always undefined!!!!
});
And I’ve added the plugin: cordova-sqlite-storage, spec="~1.4.1".
I don’t really understand whats is wrong.
Any help?
set
is an asynchronous operation. You’re not guaranteed that anything has happened until its return promise has resolved.
storage.set('name', 'Max').then(() => {
storage.get('name').then((name) => {
console.log(name);
});
});
Corin
June 16, 2016, 1:02am
3
Well, this example is not my case
As I am setting the value in one view
and trying to get the value in another view or even closing the app and opening again
and still is empty
I can say I’ve added the sql plugin too
so, I don’t quite understand whats wrong
Encountered this awhile ago. Try assigning a dbname
this.storage = new Storage(SqlStorage, { name: 'myDB' });
1 Like
Corin
June 16, 2016, 9:04pm
5
Ohh, thank you!
It works!