Currently, I am in the process of developing an Ionic 4 Angular application and utilizing Ionic 4 storage. In this context, I have successfully implemented setting and getting key-value pairs using Ionic storage. However, I am facing a challenge when trying to retrieve a key-value pair from Ionic storage and assign its value to a variable that needs to be returned. Below is the code snippet that I am currently working with:
// Setting a key-value pair
setId(){
this.storage.set('Id',this.id);
// Getting a key-value pair
getId(){
this.storage.get('Id').then((val)=>{
console.log('Id is:',val);
some_variable = val;
});
In this scenario, my main objective is to return the 'some_variable.'
// Desired functionality
getId(){
this.storage.get('Id').then((val)=>{
console.log('Id is:',val);
return some_variable = val;
});
I acknowledge that my current approach may be incorrect. Could you please guide me on how to accomplish the desired return functionality in Ionic storage retrieval?