0

I have already saved some data to Storage in Ionic 2.

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

constructer(public storage: Storage){}

this.storage.set('usertype', usertype);

Now I have to create to get data from storage. And the program logic must be to execute next functions after get data using created function in storage. How can I create Get function or build program logic?

1 Answer 1

1

Looks like if you're using Ionic2's nativeStorage module it returns a promise on resolution, so using your example you can do do something like...

import { NativeStorage } from 'ionic-native';
... ... ...

NativeStorage.setItem('usertype', usertype);

.... 

NativeStorage.getItem('usertype')
  .then(
    // everything here happens once you actually have the data
    data => console.log(data),
    error => console.error(error)
  );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.