Ionic-framework: NgZone.run() required to call Nav.setRoot() inside subscribe()

Created on 27 Apr 2016  路  2Comments  路  Source: ionic-team/ionic-framework

Short description of the problem:

When trying to call nav.setRoot(Page) from a subscribe method of a Observable/Stream the view does not update until a interaction with a controller inside the page occurs.

I have only tried with Observables, but I guess many asynchronous operations will have the same behavior.

What behavior are you expecting?

A page navigation to occur and the RootPage reference to be updated.

Steps to reproduce:

  1. Implement a Observable
  2. Subscribe to it
  3. Try to call nav.setRoot()

The code below works, but if I remove the zone.run() method, it does not.

    let auth$ = this.store.select('auth');
    auth$
      .filter(auth => auth.isAuthenticated)
      .take(1)
      .subscribe(
        () => {
          this.zone.run(
            () => { this.goToMainPage(); }
          )
        }
      );

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)
I found a workaround solution on this Stack Overflow question

And there is a discussion about it here in the ionic forum(at the bottom, since there is a lot of replies): https://forum.ionicframework.com/t/ionic2-with-real-time-data-not-updating-firebase/47189/42

This may relate to:

6297, #5912

Which Ionic Version? 1.x or 2.x
2.x
(beta.6)

Run ionic info from terminal/cmd prompt: (paste output below)

Cordova CLI: 5.4.1
Gulp version:  CLI version 3.9.0
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.6
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
ios-deploy version: 1.8.4 
ios-sim version: 5.0.6 
OS: Mac OS X El Capitan
Node Version: v4.0.0
Xcode version: Xcode 7.3 Build version 7D175 

Most helpful comment

Hey! Thanks for opening an issue with us! The next release of Ionic 2 should be upgraded to Angular 2 rc1 which includes the fix that happened with zone.js in Angular 2 beta.17.

All 2 comments

After searching @iignatov comments on many topics on the Ionic forum, I believe the issue is probably related to zone.js itself and is reported already here: https://github.com/angular/zone.js/issues/304

Hey! Thanks for opening an issue with us! The next release of Ionic 2 should be upgraded to Angular 2 rc1 which includes the fix that happened with zone.js in Angular 2 beta.17.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alan-agius4 picture alan-agius4  路  3Comments

BilelKrichen picture BilelKrichen  路  3Comments

daveshirman picture daveshirman  路  3Comments

SebastianGiro picture SebastianGiro  路  3Comments

fdnhkj picture fdnhkj  路  3Comments