gpt4 book ai didi

angularjs - 使用 firebase 7.14.6 和 @angular/fire 6.0.0 FCM 网络推送通知的 'messaging' 类型上不存在属性 'AngularFireMessaging'

转载 作者:行者123 更新时间:2023-12-04 12:12:32 26 4
gpt4 key购买 nike

在实现 FCM Background Web Notification在我的服务中出现以下错误
error TS2339: Property 'messaging' does not exist on type 'AngularFireMessaging'
message.service.ts

import { Injectable } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { BehaviorSubject } from 'rxjs'

@Injectable()
export class MessagingService {
currentMessage = new BehaviorSubject(null);
constructor(private angularFireMessaging: AngularFireMessaging) {
this.angularFireMessaging.messaging.subscribe(
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)
}
}

src/firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/7.14.6/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.14.6/firebase-messaging.js');


firebase.initializeApp({
apiKey: "xxxxxxxxxxx",
authDomain: "xxxxxxxxxxx",
databaseURL: "xxxxxxxxxxx",
projectId: "xxxxxxxxxxx",
storageBucket: "xxxxxxxxxxx",
messagingSenderId: "xxxxxxxxxxx",
appId: "xxxxxxxxxxx"
});

const messaging = firebase.messaging();

已安装的软件包
"@angular/fire": "^6.0.0",
"firebase": "^7.14.6",
"@angular/cli": "^9.1.7",

我也尝试过降级 @ Angular/火火力基地但没有成功。

最佳答案

对于错误“属性 'onMessage' 在类型 '{}' 上不存在”,我只是将对象类型添加到 _messaging,现在应用程序运行:

this.angularFireMessaging.messages.subscribe(
(_messaging: AngularFireMessaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
})
}
使用此依赖项:
"@angular/fire": "^6.0.3",
"firebase": "^7.21.0",

关于angularjs - 使用 firebase 7.14.6 和 @angular/fire 6.0.0 FCM 网络推送通知的 'messaging' 类型上不存在属性 'AngularFireMessaging',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62198333/

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