Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

How should I handle Observable.Subscribe/unSubscribe and navigation?

$
0
0

@Sulot wrote:

Hi,

I am coming from Angular 4 and I am trying to undertand navigation with ionic.

On Angular if I go from comp A to B, all variables within the A comp will be detroyed unless I have a dedicated service to store data. I don't need to unsubscribe any observable.

My aim is to go from a menuPage => componentPage then back =>menuPage...

myComponentPage has a timerService:

 this._timer = new BehaviorSubject({
            event: "pause",
            timer: this.config
        })

[...]
 startTimer() {
        this._timerState = setInterval(() => {
            this._timer.next({
                event: "continue",
                timer: this._seconds - 1
            })
        }, 1000)
    }

In Ionic I have tried push(componentPage) the .pop(), setRoot(componentPage) then setRoot(menuPage) ...etc.... I have noticed that components from my B component that have subscribed my _timer are still active... Should I unsubscribe manually ?? So it means that the view is still there somewhere ??


Secondary question :
Also, why navController service in Ionic examples and injected as public whereas Angular's good practice says to be private ?

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>