Sonia
Sonia

Reputation: 41

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.

Upvotes: 3

Views: 1445

Answers (1)

Enginer
Enginer

Reputation: 3128

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

Upvotes: 2

Related Questions