Does ionic-native *really* ensure that native events trigger change detection in Angular 2?


#1

The ionic-native docs state that

Ionic Native wraps plugin callbacks in a Promise or an Observable, providing a common interface for all plugins and ensuring that native events trigger change detection in Angular 2.

AFAIK, for Promises this is handled by zone.js which wraps the native Promise object with a “zone aware promise”. So any ionic-native plugin method returning Promises should be safe OOTB.

But what about Obervables? I’ve been skimming through both the zone.js and ionic-native sources, but found nothing that would convince me that native events reported using Observables actually trigger change detection.

This is also supported by my experience with the BLE plugin, where I have to wrap every BLE notification with NgZone.run() for change detection to occur when receiving BLE data. Others seem to have similar issues.

So, how does ionic-native actually ensure that change detection is invoked on native events when using Observables? Maybe (hopefully) I’m just missing something here, but my experience with Observables as returned by BLE.startNotification() suggests otherwise…


#2

I’ve been facing exactly the same issue. I had originally not realized that automatic change detection was working for native events using Promises (because so far, I had only subscribed to those native methods returning Observables), but I confirm that it does seem to work for Promises and NOT work for Observables.

I too am stuck wrapping all callbacks with NgZone.run() calls.

Is there some additional step that needs to be done in order for this to work for Observables too?


#3

See https://github.com/driftyco/ionic-native/issues/823