模块“@angular/fire/messaging”没有导出成员“AngularFireMessaging”.ts(2305)

问题描述 投票:0回答:1

我正在尝试使用 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”,

angular firebase import firebase-cloud-messaging angularfire
1个回答
12
投票

改成怎么样

import { AngularFireMessaging } from '@angular/fire/compat/messaging';

参考这里

© www.soinside.com 2019 - 2024. All rights reserved.