Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i get value from NativeStorage.getString() Without Using Callbacks? #144

Open
elkhalifte opened this issue Aug 26, 2019 · 1 comment

Comments

@elkhalifte
Copy link

elkhalifte commented Aug 26, 2019

I Have Used This Plugin cordova-plugin-nativestorage in My Phonegap app . The Plugin Works fine.

I Wonder If There Is any trick to get values from Nativestorage.getItem() without callbacks

This My Code i Call app.getstring('ref_string'); To get Saved Data in ref_string Key as an Alert.

When I Try To save it To Input Text as a Value I Got Undefined.

getstring:function(key){

ativeStorage.getString(key,function (result) {


      alert('String Is '+result);},

         function (e) {

      alert('Error '+e);});
}

@J3m5
Copy link

J3m5 commented Sep 5, 2019

The solution would be to wrap the methods in a promise.
That would make them asynchronous.

const getItem = key => 
  new Promise((resolve, reject) => NativeStorage.getItem(key, resolve, reject))

// in an async function
const value = await getItem("key");

I didn't test it, but it's certainly the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants