Error on BackgroundMode.on

App.ts:

 import {BackgroundMode} from 'ionic-native';

      platform.ready().then(() => {

           BackgroundMode.enable(); 

           BackgroundMode.on('activated', function(){
             console.log('ACTIVATED');
           });
   }

Error caused by calling on function:

 10    301886   group    EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined
 11    301889   error    EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined
 12    301891   error    STACKTRACE:
 13    301892   error    Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined
     at resolvePromise (http://192.168.56.1:8100/build/js/zone.js:538:32)
     at http://192.168.56.1:8100/build/js/zone.js:574:18
     at ZoneDelegate.invokeTask (http://192.168.56.1:8100/build/js/zone.js:356:38)
     at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (http://192.168.56.1:8100/build/js/app.bundle.js:36310:41)
     at ZoneDelegate.invokeTask (http://192.168.56.1:8100/build/js/zone.js:355:43)
     at Zone.runTask (http://192.168.56.1:8100/build/js/zone.js:256:48)
     at drainMicroTaskQueue (http://192.168.56.1:8100/build/js/zone.js:474:36)
     at ZoneTask.invoke (http://192.168.56.1:8100/build/js/zone.js:426:22)
 14    301896   groupEnd
 15    301901   error    Unhandled Promise rejection:, Cannot read property 'apply' of undefined, ; Zone:, angular, ; Task:, Promise.then, ; Value:, [object Object]

The documentation seems to be wrong because it say ‘on’ receives just one parameter called the eventName. In fact it should receive a callback too.

from your other post it looks like you got it fixed. if that’s correct could you post the working code, for future reference?

There’s two problems here.

First the documentation is wrong.

In my code I put an second argument, which don’t causes compiler errors but causes an execution error shown above.

@NatnaelOsorio, can you please share with us also the solution?

BackgroundMode.on('activate', function() {
});

EXCEPTION: TypeError: Cannot read property 'apply' of undefined
browser_adapter.js:84 EXCEPTION: TypeError: Cannot read property 'apply' of undefinedBrowserDomAdapter.logError @ browser_adapter.js:84BrowserDomAdapter.logGroup @ browser_adapter.js:94ExceptionHandler.call @ exception_handler.js:65(anonymous function) @ application_ref.js:337EventEmitter.subscribe.schedulerFn @ async.js:139SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:127NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:124NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:74ZoneDelegate.handleError @ zone.js:327Zone.runTask @ zone.js:259ZoneTask.invoke @ zone.js:423
browser_adapter.js:84 STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.js:84ExceptionHandler.call @ exception_handler.js:67(anonymous function) @ application_ref.js:337EventEmitter.subscribe.schedulerFn @ async.js:139SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:127NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:124NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:74ZoneDelegate.handleError @ zone.js:327Zone.runTask @ zone.js:259ZoneTask.invoke @ zone.js:423
browser_adapter.js:84 TypeError: Cannot read property 'apply' of undefined
    at callCordovaPlugin (plugin.js:81)
    at Function.exports.wrap (plugin.js:221)
    at Function.value [as on] (plugin.js:284)
    at SafeSubscriber._next (app.ts:70)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:225)
    at SafeSubscriber.next (Subscriber.js:174)
    at Subscriber._next (Subscriber.js:124)
    at Subscriber.next (Subscriber.js:88)
    at XMLHttpRequest.XHRConnection.response.Observable_1.Observable.onLoad (xhr_backend.js:68)
    at ZoneDelegate.invokeTask (zone.js:356)BrowserDomAdapter.logError @ browser_adapter.js:84ExceptionHandler.call @ exception_handler.js:68(anonymous function) @ application_ref.js:337EventEmitter.subscribe.schedulerFn @ async.js:139SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:127NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:124NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:74ZoneDelegate.handleError @ zone.js:327Zone.runTask @ zone.js:259ZoneTask.invoke @ zone.js:423
plugin.js:81 Uncaught TypeError: Cannot read property 'apply' of undefined

There’s no solution yet.

Not good, I opened a issue on github