简体   繁体   English

错误TypeError:firebase.messaging不是函数

[英]ERROR TypeError: firebase.messaging is not a function

I'm getting error, ERROR TypeError: firebase.messaging is not a function Whats wrong with it ? 我遇到错误,错误TypeError:firebase.messaging不是一个函数怎么了?

 import { Injectable } from '@angular/core'; import { AngularFireDatabase } from 'angularfire2/database'; import { AngularFireAuth} from 'angularfire2/auth'; import * as firebase from 'firebase/app'; import 'rxjs/add/operator/take'; import { BehaviorSubject} from 'rxjs/BehaviorSubject'; @Injectable() export class MessagingService { messaging = firebase.messaging(); currentMessage = new BehaviorSubject(null); constructor(private db: AngularFireDatabase, private afAuth: AngularFireAuth) { } private updateToken(token) { this.afAuth.authState.take(1).subscribe(user => { if (!user) { return; } const data = { [user.uid]: token }; this.db.object('fcmTokens/').update(data); }); } getPermission() { this.messaging.requestPermission() .then(() => { console.log('Notification permission granted.'); return this.messaging.getToken(); }) .then(token => { console.log(token); this.updateToken(token); }) .catch((err) => { console.log('Unable to get permission to notify.', err); }); } receiveMessage() { this.messaging.onMessage((payload) => { console.log('Message received. ', payload); this.currentMessage.next(payload); }); } } 

ERROR TypeError: firebase.messaging is not a function I'm having big probleems with that error, I don't have any idea how to fix that, please help me repair that code. ERROR TypeError: firebase.messaging is not a function firebase.messaging ERROR TypeError: firebase.messaging is not a function我对该错误有很大的疑问,我不知道如何解决该问题,请帮助我修复该代码。 I've done everything like an example, but it doesn't work. 我已经完成了所有工作,例如一个示例,但是没有用。 thank you so much for your answers. 非常感谢您的回答。

Try changing 尝试改变

import * as firebase from 'firebase/app';

to

import * as firebase from 'firebase';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 firebase.messaging 不是 Angular 中的 function 9 - firebase.messaging is not a function in Angular 9 使用AngularFirestore和firebase的“ ERROR TypeError:Object(…)不是函数” - “ERROR TypeError: Object(…) is not a function” using AngularFirestore and firebase Angular 5 Firebase-错误TypeError:(中间值).map不是函数 - Angular 5 firebase - ERROR TypeError: (intermediate value).map is not a function 角度2:错误TypeError:..不是函数 - Angular 2: ERROR TypeError: .. is not a function 错误TypeError:.indexOf不是函数 - ERROR TypeError: .indexOf is not a function "Angular 6: ERROR TypeError: "... is not a function" - 但它是" - Angular 6: ERROR TypeError: "... is not a function" - but it is Angular6 / Firebase2 | 错误TypeError:this.clientService.getClients(...)。subscribe不是函数 - Angular6/Firebase2 | ERROR TypeError: this.clientService.getClients(…).subscribe is not a function TypeError:Object(…)不是函数,正在从Firebase调用数据 - TypeError: Object(…) is not a function, calling data from firebase TypeError:readFile $(...)。mergeMap不是Firebase服务函数中的函数 - TypeError: readFile$(…).mergeMap is not a function in firebase serve functions ionic firebase-TypeError:Object(…)在Firebase.getToken中不是函数 - ionic firebase - TypeError: Object(…) is not a function at Firebase.getToken
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM