I am using Ionic 5 with Firebase Realtime Database and Firestore (angularfire) and Angular Routing. On most pages I am streaming databasecontent. Because of the Ionic-lifecycle the pages are not destroyed when leaving the view. As I would do in Angular, I declare my Observables in ngOnInit.
public data$: Observable<Data[]>;
ngOnInit() {
this.data$ = this.dataService.retrieveData();
In my template I am using async pipe.
The async pipe would automaticly unsubscribe when the component is destroyed. But because of the Ionic lifecycle this does not happen, when leaving the view.
Question 1: Is it good practice to keep the databasestreaming open when leaving views (and only unsubscribe when onNgDestroy is called)?
Question 2: If it is preferred to use the lifecycle hooks (i.e. ionViewWillEnter, ionViewWillLeave) it would not be possible to use the async pipe, so I have to do subscribing an unsubscribing on my own. Not using async pipes sounds unreasonable. In which usecases does that make sense? the question in detail and share your code, configuration, and other relevant info.
1 post - 1 participant