错误:尚未创建Firebase应用"[DEFAULT]" [英] Error: No Firebase App '[DEFAULT]' has been created

查看:110
本文介绍了错误:尚未创建Firebase应用"[DEFAULT]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ionic2,当我进入localhost:8100(在执行ionic serve之后)时,收到以下错误,您可以在下图中看到.

I'm using Ionic2 and when I go to localhost:8100 (after doing ionic serve) I receive the error you can see in the following image.

app.component.ts 看起来像这样:

import firebase from 'firebase';
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { HomePage } from '../pages/home/home';

@Component({
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
  rootPage = HomePage;

  constructor(platform: Platform) {
    platform.ready().then(() => {


      var config = {
        apiKey: ".....",
        authDomain: "......",
        databaseURL: ".....",
        storageBucket: ".....",
        messagingSenderId: "......"
      };

      firebase.initializeApp(config);
      StatusBar.styleDefault();
    });
  }
}

app.module.ts

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage 
  ],
  providers: []
})
export class AppModule {}

我的系统信息:

Cordova CLI:6.3.1

Cordova CLI: 6.3.1

离子框架版本:2.0.0-rc.1

Ionic Framework Version: 2.0.0-rc.1

离子CLI版本:2.1.1

Ionic CLI Version: 2.1.1

Ionic App Lib版本:2.1.1

Ionic App Lib Version: 2.1.1

Ionic应用程序脚本版本:0.0.36

Ionic App Scripts Version: 0.0.36

操作系统:发行商ID:Ubuntu说明:Ubuntu 16.04.1 LTS

OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS

节点版本:v4.2.6

Node Version: v4.2.6

推荐答案

我遇到了同样的问题,也许我有解决方案(对我有用).

I had the same problem and perhaps I have a solution (works for me).

我已经从我的app.components.ts中完全删除了Firebase初始化,并将其添加到NGModule之前的app.module.ts中,例如:

I've deleted firebase initialization from my app.components.ts completely and added it in app.module.ts BEFORE NGModule, e.g.:

    ...
    import * as firebase from 'firebase';

    export const firebaseConfig = {
      apiKey: "",
      authDomain: ".firebaseapp.com",
      databaseURL: "https://.firebaseio.com",
      storageBucket: ".appspot.com",
      messagingSenderId: ""
    };

    firebase.initializeApp(firebaseConfig); //<-- where the magic happens

    @NgModule({
    ...

现在我可以在我的服务中使用它了(别忘了在app.module.ts'providers:[yourService]'中包含您的服务)

Now I can use it in my Service (don't forget to include your service in app.module.ts 'providers: [yourService]')

import firebase from 'firebase';

@Injectable()
export class yourService {
//Here you can use firebase.database(); or firebase.auth(); as you wish and it should work. 
}

希望这对您有用!

这篇关于错误:尚未创建Firebase应用"[DEFAULT]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆