Hello guys,
I finally figured out how to save data object from an array to a list inside ionic storage.
saveToFav(item) {
this.storage.get('myList').then((list) => {
if(list!= null)
{
list.push(item);
this.storage.set('myList', list);
}
else
{
let list = [];
list.push(item);
this.storage.set('myList', list);
}
});
}
}}
This will save a javascript object with several attributes to storage but I see only null being stored.
When I save five items, I get this on chrome browser’s inspect -> application
myList [null,null,null,null,null]
It’s clearly saving items to myList but they’re all nulled.
Because of this error, I’m unable to load the list on a favorite page which is fetching the items using:
this.storage.ready().then(() => {
return this.storage.get('myList').then((list) => {
this.itemlist = list;
console.log(list);
});
});
and favorite page HTML:
<div style="width: 100%; color: black;" *ngFor="let item of list">
<br><br><br><br><br>
<h1>{{item.name}}</h1>
<p>{{item.description}}</p>
</div>
Any idea? how can I save javascript object properly?
Each javascript object has several attributes:
private items: any[] = [
{
"name": "item 01",
"description": "this is item 01",
"id": "1"
},
{
"name": "item 02",
"description": "this is item 02",
"id": "2"
},
{
"name": "item 03",
"description": "this is item 03",
"id": "3"
},
{
"name": "item 04",
"description":"this is item 04",
"id":"4"
}
]
Thanks in advance