Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 Storage for browser and mobile

Before RC0 Ionic 2 had the possibility to use local storage like this:

storage = new LocalStorage(SqlStorage, options);

I used this in my app and it worked in both, browser (ionic serve) and mobile (build/run).

Now there is a only LocalStorage or SecureStorage, which apparently both do not work in browser (serve).

Is there any other possibility to use a storage/database system which works for both, browser and mobile?

I am glad about any help.

like image 368
Sonia Avatar asked Dec 13 '25 07:12

Sonia


1 Answers

Now (Ionic v2.0.1) you can use Storage like:

import { Storage } from '@ionic/storage';

export class MyApp {
  constructor(storage: Storage) {

     storage.ready().then(() => {

       // set a key/value
       storage.set('name', 'Max');

       // Or to get a key/value pair
       storage.get('age').then((val) => {
         console.log('Your age is', val);
       })
     });
  }
}

more datails on https://ionicframework.com/docs/v2/storage

like image 151
Enginer Avatar answered Dec 16 '25 11:12

Enginer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!