I have an project in ionic 5. I am using ionic storage. But storage is not setting value. Neither it is giving error. Please help me out this.
It would be supremely useful to anybody trying to help you if you could put together a publicly-accessible MCVE.
I have the same issue showing up recently. I’ve tried to reproduce it by scaffolding a new app via ionic start
and then the problem does not show up. The only code I’ve added to app.component.ts
is
await this.storage.set('test-key', 'test-value');
const result = await this.storage.get('test-key');
console.log('result = ' + result);
This code, in the test app, where I’ve tried to reproduce the problem did not reproduce the problem and everything worked, I saw the expected result = test-value
but in my own app, I still get result = undefined
with the same code.
I cannot provide my actual code because it is a huge project and also a private one for now (it will be open source later).
I see one difference between the two apps when printing the value of this.storage
service. In the mini scafolded app, where things work, we see, for this.storage
:
app.component.ts:77 storage obj =
Storage {_driver: null, _dbPromise: ZoneAwarePromise}
_dbPromise: ZoneAwarePromise
__zone_symbol__state: true
__zone_symbol__value: LocalForage {INDEXEDDB: "asyncStorage", WEBSQL: "webSQLStorage", LOCALSTORAGE: "localStorageWrapper", _defaultConfig: {…}, _config: {…}, …}
Symbol(Symbol.species): (...)
Symbol(Symbol.toStringTag): (...)
__proto__: Object
_driver: "webSQLStorage"
driver: (...)
__proto__: Object
while in my app, where storage is not working, we see, for this.storage
:
storage obj =
Storage {_driver: null, _dbPromise: ZoneAwarePromise}
_dbPromise: ZoneAwarePromise
__zone_symbol__state: true
__zone_symbol__value: {getItem: ƒ, setItem: ƒ, removeItem: ƒ, clear: ƒ, length: ƒ, …}
Symbol(Symbol.species): (...)
Symbol(Symbol.toStringTag): (...)
__proto__: Object
_driver: null
driver: (...)
__proto__: Object
In other words the storage service object has _driver
as null in my app where the problem occurs, but in the scafolded app where the problem does not occur, it is webSQLStorage
– strange because my app has been scafolded in the exact same manner, with the same package versions as the successful working app above.
Both apps ran in desktop browser Chromium 83.0.4103.116 (Developer Build) built on Debian 10.4, running on Debian 10.5 (64-bit)
.
I hope this sheds some light on your investigation, if you pursue one. This is a real problem. There seems to be some kind of interference from something else in my app, with the webSQLStorage
not registering in the bigger (real) app. If I find out any more info, I will post here.
Please see (and potentially continue discussion in) this thread.