我正在尝试使用 Angular 和 Firebase 来处理推送通知。 在服务工作者文件中添加 firebase 包后,我遇到了上述问题
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);
}
)
}
requestPermission() {
this.angularFireMessaging.requestToken.subscribe(
(token: any) => {
console.log(token);
},
(err: any) => {
console.error('Unable to get permission to notify.', err);
}
);
}
receiveMessage() {
this.angularFireMessaging.messages.subscribe(
(payload: null) => {
console.log("new message received. ", payload);
this.currentMessage.next(payload);
})
}
}
这是我的代码 Package.json详细信息如下 “@角度/火”:“^7.4.1”, “firebase”:“^9.9.2”,