Hi guys, i’m trying to make an app for a congress based on the ionic-conference-app template, i’ve a problem with the “favorites”, they work perfectly but when I close the app on a mobile or reload it in a browser, there is no more favs.
I want to save them but with no user session, it just change something on the app on each phone to remember favs.
I try things with ionicStorage but it doesn’t work and I don’t see how can I do to save them after app closing, here is the repository of the theme : https://github.com/driftyco/ionic-conference-app
If somebody can help me, it will be very cool !
Adrien
Yes, i try with storage.set() and storage.get(), here is the code :
addFavorite(slidingItem: ItemSliding, sessionData: any) {
if (this.user.hasFavorite(sessionData.name)) {
this.removeFavorite(slidingItem, sessionData, 'Cette session est déjà dans vos Favoris');
} else {
// remember this session as a user favorite
this.user.addFavorite(sessionData.name);
let alert = this.alertCtrl.create({
title: 'Favoris ajouté',
buttons: [{
text: 'OK',
handler: () => {
slidingItem.close();
}
}]
});
// now present the alert on top of all other content
alert.present();
console.log(sessionData);
}
this.storage.get('Favs').then((data:any[]) => {
if(data != null)
{
data.push(sessionData);
this.storage.set('Favs', data);
}
else
{
let array = [];
array.push(sessionData);
this.storage.set('Favs', array);
}
});
}
but I have this error : "Uncaught (in promise): TypeError: data.push is not a function. (In ‘data.push(sessionData)’, ‘data.push’ is undefined)"
I don’t know how to solve it