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…