The way i like is convert array of json into string and store it and during fetching convert string to json
Use json.parse() and json.stringify().
Then use ngfor in template
Yes, that’s like creating a model.
Thanks again! I will try it.
I think ionic storage is definitely the least developer friendly part of ionic. It’s like guess and try ill it works.
This saves item with its unique key id and all attributes…
and I created interface for items.
Here’ favorite page TS which I’m trying to load all items:
import { Component } from '@angular/core';
import { NavController, NavParams, Platform } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { Observable } from 'rxjs/Observable'
import {StorageItem } from './storageitem';
@Component({
selector: 'page-favourites',
templateUrl: 'favourites.html'
})
export class FavouritesPage {
isFavorite = false;
submitted: boolean = false;
item: any;
key: any;
storageItems: Array<StorageItem>;
constructor(
public platform: Platform,
private storage: Storage,
public navCtrl: NavController,
public navParams: NavParams,
) {
this.storageItems = [];
}
ionViewDidLoad() {
this.storage.forEach( (value) => {
this.storageItems = value;
})
}
and favorite page html:
<div *ngFor="let item of storageItems">
<h1>{{item.name}}</h1>
</div>
I’m just error messages ERROR Error: Error trying to diff ''. Only arrays and iterables are allowed
Any idea?
I can still see items stored in Chrome’s inspect -> application -> webSQL page.
and I can call items up in console too. So it’s saving items correctly… but they can’t be parsed.