gpt4 book ai didi

Firebase 导入未在构造函数 ionic Native 中初始化

转载 作者:行者123 更新时间:2023-12-02 22:15:06 24 4
gpt4 key购买 nike

我正在研究ionic fcm 推送通知。我已经导入了

import { Firebase } from '@ionic-native/firebase'; 但我无法在构造函数中初始化 Firebase 。这是我的代码

import { Injectable } from '@angular/core';
import { Firebase } from '@ionic-native/firebase';
import { Platform } from 'ionic-angular';
import {HttpClient, HttpHeaders} from '@angular/common/http';

@Injectable()
export class FcmProvider {

constructor(private platform: Platform,
public firebaseNative:Firebase,
public http: HttpClient) {
console.log('Hello FcmProvider Provider');
}

// Get permission from the user
async getToken() {
let token;

if (this.platform.is('android')) {
token = await this.firebaseNative.getToken()
}
}
}
}

我在

处遇到错误
constructor(private platform: Platform, 
public firebaseNative:Firebase,

它说的是

Cannot find name Firebase

我正在关注this article .

我已经安装了npm i @ionic-native/firebasenpm i @ionic-native/fcm软件包仍然没有得到它。欲了解更多信息,请参阅屏幕截图:

enter image description here

更新:Package.Json

  "private": true,
"dependencies": {
"@angular/common": "^7.2.2",
"@angular/core": "^7.2.2",
"@angular/forms": "^7.2.2",
"@angular/http": "^7.2.2",
"@angular/platform-browser": "^7.2.2",
"@angular/platform-browser-dynamic": "^7.2.2",
"@angular/router": "^7.2.2",
"@ionic-native/core": "^5.0.0",
"@ionic-native/fcm": "^5.1.0",
"@ionic-native/firebase": "^5.1.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^4.0.0",
"angularfire2": "^5.1.1",
"cordova-plugin-firebase": "2.0.5",
"core-js": "^2.5.4",
"firebase": "^5.8.3",
"ionic-angular": "^3.1.0",
"nvm-win": "^0.2.4",
"reinstall": "^2.0.0",
"rxjs": "~6.3.3",
"zone.js": "~0.8.29"
},
}

如何解决这个问题?

最佳答案

可能您正在使用 ionic 版本 3 项目并且您正在使用 最新版本 ionic V4。

first solution

如 v4 文档中所述,在导入路径的最后使用“ngx”

喜欢:-

从“@ionic-native/firebase/ngx”导入{Firebase};引用:https://ionicframework.com/docs/native/firebase

Second Solution

首先删除现有的插件ionic cordova 插件删除 cordova-plugin-firebase

重新添加

ionic cordova 插件添加 cordova-plugin-firebase

npm install --save @ionic-native/firebase@4

请记住遵循doc v3以进一步实现

https://ionicframework.com/docs/v3/native/firebase/

关于Firebase 导入未在构造函数 ionic Native 中初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54765149/

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