gpt4 book ai didi

angular - 未处理的 promise 拒绝 : this. _next 不是函数:@angular/fire/messaging 中的区域

转载 作者:行者123 更新时间:2023-12-03 23:09:09 25 4
gpt4 key购买 nike

当我在前台接收 Firebase 推送通知时,使用 @angular/fire/messaging .方法是:

  this.angularFireMessaging.messages.subscribe(
(payload) => {
console.log("new message received. ", payload);
this.currentMessage.next(payload);
})

让我分享我的完整代码: PushNotificationsService Code我已经写了。

我的 Angular-cli 版本:
Angular CLI: 8.1.3
Node: 12.4.0
OS: linux x64
Angular: 8.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.801.3
@angular-devkit/build-angular 0.801.3
@angular-devkit/build-optimizer 0.801.3
@angular-devkit/build-webpack 0.801.3
@angular-devkit/core 8.1.3
@angular-devkit/schematics 8.1.3
@angular/fire 5.3.0
@ngtools/webpack 8.1.3
@schematics/angular 8.1.3
@schematics/update 0.801.3
rxjs 6.4.0
typescript 3.4.5
webpack 4.35.2

让我分享我的 package.json 文件: package.json

当我在前台收到消息时出现以下错误:
Unhandled Promise rejection: this._next is not a function ; Zone: <root> ; Task: ServiceWorkerContainer.addEventListener:message ; Value: TypeError: "this._next is not a function"
next RxJS
messageEventListener index.esm.js:1046
step tslib.es6.js:99
verb tslib.es6.js:80
__awaiter tslib.es6.js:73
ZoneAwarePromise Angular
__awaiter tslib.es6.js:69
messageEventListener index.esm.js:1035
WindowController index.esm.js:876
Angular 5
next@http://localhost:4200/vendor.js:111323:18
./node_modules/@firebase/messaging/dist/index.esm.js/WindowController.prototype.messageEventListener/</<@http://localhost:4200/firebase-messaging.js:2418:34
step@http://localhost:4200/vendor.js:127272:23
verb/<@http://localhost:4200/vendor.js:127253:53
__awaiter/<@http://localhost:4200/vendor.js:127246:71
ZoneAwarePromise@http://localhost:4200/polyfills.js:3882:29
__awaiter@http://localhost:4200/vendor.js:127242:12
./node_modules/@firebase/messaging/dist/index.esm.js/WindowController.prototype.messageEventListener@http://localhost:4200/firebase-messaging.js:2407:71
WindowController/<@http://localhost:4200/firebase-messaging.js:2248:26
invokeTask@http://localhost:4200/polyfills.js:3397:31
runTask@http://localhost:4200/polyfills.js:3174:47
invokeTask@http://localhost:4200/polyfills.js:3471:34
invokeTask@http://localhost:4200/polyfills.js:4609:14
globalZoneAwareCallback@http://localhost:4200/polyfills.js:4635:27

任何帮助都是非常可观的! CODE: GITHUB REPO LINK

我已经在 GitHub 代码中从 firebase 更新了我的 key

最佳答案

有解决方法。

您需要稍微修改您的自定义消息服务。

在构造函数中,您需要替换以下代码

this.angularFireMessaging.messaging.subscribe(
(_messaging: any) = > {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
messaging._next = (payload: any) = > {
console.log(payload);
};
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
);

接着就,随即

this.angularFireMessaging.messaging.subscribe(
(_messaging: any) = > {
// _messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging._next = (payload: any) = > {
console.log(payload);
};
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
);

然后,即使您处于前台,您也会收到推送通知。

关于angular - 未处理的 promise 拒绝 : this. _next 不是函数:@angular/fire/messaging 中的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59961620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com