ionic-storage

Ionic Storage is not working on Android device

梦想的初衷 提交于 2020-01-06 07:15:08
问题 I'm new to the Ionic Framework, and I'm doing an app that preserves the user login so it can show a different page when user is logged. And for doing this, I'm saving the user ID into the local storage. This works fine when I do ionic serve and testing the code on browser, but it doesn't work on my Android device (so I run ionic cordova run android ). Why? I have set the Storage right by using IonicStorageModule.forRoot() in app.module.ts -> imports[...] . Here's my code and my Ionic specs:

How to use Ionic Storage to store json object from api with ionic 3?

老子叫甜甜 提交于 2019-12-23 04:22:49
问题 I would like to know how to use Ionic Storage to store Json Object with Ionic 3. I am finding it difficult as there are no examples for the ionic 3 and i am stuck. Nothing on the net seems to be updated. A supporting example for Ionic Storage would be of great use. Thank you in advance. 回答1: Yes, you can store JSON objects in Ionic storage. let your_json_object = { "name":"John", "age":30, "car":null }; // set a key/value storage.set('my-json', your_json_object); // to get a key/value pair

Typescript returning boolean after promise resolved

一笑奈何 提交于 2019-12-22 04:19:09
问题 I'm trying to return a boolean after a promise resolves but typescript gives an error saying A 'get' accessor must return a value. my code looks like. get tokenValid(): boolean { // Check if current time is past access token's expiration this.storage.get('expires_at').then((expiresAt) => { return Date.now() < expiresAt; }).catch((err) => { return false }); } This code is for Ionic 3 Application and the storage is Ionic Storage instance. 回答1: You can return a Promise that resolves to a boolean

Typescript returning boolean after promise resolved

情到浓时终转凉″ 提交于 2019-12-05 03:16:24
I'm trying to return a boolean after a promise resolves but typescript gives an error saying A 'get' accessor must return a value. my code looks like. get tokenValid(): boolean { // Check if current time is past access token's expiration this.storage.get('expires_at').then((expiresAt) => { return Date.now() < expiresAt; }).catch((err) => { return false }); } This code is for Ionic 3 Application and the storage is Ionic Storage instance. You can return a Promise that resolves to a boolean like this: get tokenValid(): Promise<boolean> { // | // |----- Note this additional return statement. // v