如何在Angular2 / TypeScript / AngularFire2中实例化Firebase云消息传递?
这里描述了JavaScript:
https://firebase.google.com/docs/cloud-messaging/js/client
firebase.messaging()函数将Firebase应用程序实例作为可选参数.
原文链接:https://www.f2er.com/angularjs/141649.html要使用AngularFire2连接它,您可以让AngularFire2 perform the app initialization创建Firebase应用程序实例,然后注入应用程序实例(例如,进入服务)并将其传递给firebase.messaging(),如下所示:
import { Inject,Injectable } from "@angular/core"; import { FirebaseApp } from "angularfire2"; import * as firebase from 'firebase'; @Injectable() export class SomeService { private _messaging: firebase.messaging.Messaging; constructor(@Inject(FirebaseApp) private _firebaseApp: firebase.app.App) { this._messaging = firebase.messaging(this._firebaseApp); this._messaging.requestPermission() .then(() => { ... }) .catch((error) => { ... }); } }
您需要设置您引用的文章中提到的web app manifest.这是我不熟悉的事情.