Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70793

Ionic 4 - How to assign storage value to variable

$
0
0

@littlefloralbunny wrote:

Hello there!

I am building an app in which I store and retrieve items from a device’s local storage using the ionic storage package. I have no problems with storing items, but I am having trouble with retrieving the stored values and using them as a variable.

For example, say I have this item in storage:

person = {
name: "Angela",
age: "32"
}

this.storage.set("01", person);

I want to get this item from storage and display it to a html page like so:

<p> {{ person.name }} </p>
<p> {{ person.age }} </p>

To do this, I would need to assign it to a variable called “person” when the page loads.
If I were to use this.person = this.storage.get("01"), I have a blank page.
If I use this.storage.get("01").then(item => (this.person = item)), this.person is undefined.

How can I get the value of the stored item and assign it to a class variable?

Thanks in advance :slight_smile:

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>