0

In an ionic app, say I have several different pages. Let's say I make some database query in each of the different pages where I assign a class variable to the result of the db query. Like so:

bills: Observable<any[]>;

this.bills = db.list(this.constants.BILLS_ROOT_NODE, ref => 
ref.limitToFirst(25)).valueChanges();

Should I be unsubscribing or managing these subscriptions somehow? Does each subscription die once I navigate to a new page? What happens if two different pages end up requesting a similar node, should that be pulled out into a provider and then injected? Should all of my database calls be pulled out into a provider?

Robert Brand
  • 300
  • 2
  • 8
  • this is too broad, but in very short words, you have to unsubscribe all subscriptions if there is no need for it before you leave the page, or it will lead you to memory leaks, but please keep your question into 1 problem, not tens of questions at once, or would be better to see a full tutorial. – Al-Mothafar Dec 08 '17 at 21:30
  • Is there a link/documentation to back up your statement about unsubscribing? – Robert Brand Dec 10 '17 at 17:37
  • If you Google it, you will find many talking about it, anyway it is something basic if you see some tutorials, here some links https://stackoverflow.com/questions/38008334 , http://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/ and https://netbasal.com/when-to-unsubscribe-in-angular-d61c6b21bad3 – Al-Mothafar Dec 10 '17 at 18:04

0 Answers0