hello World,
when a user login, i save user data in storage
when a user login, user data is saved in storage,
getStorage() {
this.storages.getObject().then((data) => {
this.user = data;
});
}
this is the code for a get from a API and i added a loading controller
this.http.get('https://thewebsite/api/book/view/' + this.id).subscribe(response => {
this.book = response;
this.storage.set('book chapters', response['book_chapters']).then(() => {
console.log('books saved to storage');
this.storage.get('book chapters').then(val => {
this.bookchapters = val;
if (this.user !=null){
setTimeout(() => {
this.inform();
}, 1000);
}
}
});
});
});
this is the code for loading controller, if there
async inform() {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Go to last read Chapter ',
message: 'want to read saved Chapter?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: 'Confirm',
handler: () => {
}
}
],
});
await alert.present();
}
my question, i have a (click)=“goBack()” button to allow user to go back home page, but due to the heavy load, the get request is still working in the background. resulting to Loading Controller alert message when its back to home page.
i did not learn how to use Listener or Observables rxjs so .unsubscribe() does not work when i tried to unsubscribe the http.get…
is there a way to stop all the get or loading of data when the back button is clicked?
thank you
1 post - 1 participant