ngIf not working with subscribe if I dont use NgZone

Okay just wanted to make sure the basics were already tested before digging deeper. So the simple answer is that the network connect observable updates outside of angular zone.

You can see this by just logging out a simple test.

ionViewDidLoad() {
  console.log(`ionViewDidLoad inside angular zone?: ${NgZone.isInAngularZone()}`);

  this.connectSubscription = this.network.onConnect().subscribe(() => {
    console.log(`Subscription inside angular zone?: ${NgZone.isInAngularZone()}`);
  });
}

This will log true for the ionViewDidLoad check, but false for the subscribe check

This is a known issue and there is already a bug opened for it: https://github.com/ionic-team/ionic-native/issues/2202

1 Like