-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Version info
Angular: 6.0.9
Firebase: 5.4.1
AngularFire: 5.0.0-rc.12
How to reproduce these conditions
const msg: AngularFireMessaging = this.msg;
msg.tokenChanges.subscribe(
(token) => console.log('@@@ tokenchange', token),
(err) => console.log('@@@ tokenchange ERROR', err),
);
Debug output
** Errors in the JavaScript console **
@@@ tokenchange ERROR TypeError: this.onTokenRefreshInternal is not a function
at Observable.push../node_modules/@firebase/messaging/dist/index.esm.js.WindowController.onTokenRefresh [as _subscribe] (index.esm.js:1883)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:42)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:28)
at subscribeTo.js:21
at subscribeToResult (subscribeToResult.js:6)
at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/switchMap.js.SwitchMapSubscriber._innerSub (switchMap.js:47)
at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/switchMap.js.SwitchMapSubscriber._next (switchMap.js:40)
at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at angularfire2.js:59
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
Expected behavior
No error. Problem seems to be in messaging.ts: https://github.com/angular/angularfire2/blob/185943f60012d8c3dcf7cc26413e3278f9e426be/src/messaging/messaging.ts#L56
const tokenChanges = this.messaging.pipe(
switchMap(messaging => new Observable(messaging.onTokenRefresh)),
runOutsideAngular(zone)
);
messaging.onTokenRefresh is not bound. As a workaround I've done this myself and this fixes the issue:
const _messaging = app.messaging();
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
PS. other observables in messaging.ts seem to follow the same pattern and do not bind to this
Tolitech, bradyisom, codediodeio, vandres, sheikalthaf and 3 more
Metadata
Metadata
Assignees
Labels
No labels