I\'m trying to save a data array object with many attributes to a favorite list using Ionic SQlite storage.
For instance, I have a data array in data provider:
make a function to save the favorites:
addFavorite(favorite:any):void{
let favorites = this.storage.get('favorites');
if(favorites){
favorites.push(favorite);
this.storage.set('favorites', favorites);
}else{
favorites = [];
favorites.push(favorite);
this.storage.set('favorites',favorites);
}
then to get favorites add this function:
getFavorites():any{
let favorites = this.storage.get("favorites");
return favorites;
}
for ionic: if you are using @ionic/storage
then to load items use async pipe:
getFavorites():Promise<any>{
let favorites = this.storage.get("favorites");
return favorites;
}
then to access them in *ngFor do this:
<div *ngFor="let item of getFavorites() | async">
<div>{{item.name}}</div>
</div>