Firebase 在 angularfire2 中返回“app/bad-app-name”

Cha*_*cay 5 javascript firebase angularfire2 angular

在我的 Angular 应用程序中,Firebase 返回一个显示bad-app-name为代码的错误。我在 angular 应用程序中使用 angularfire2。

我已经仔细检查了 Firebase 配置,没问题,那么如何解决这个错误。

app.components.ts

import { Component, OnInit } from '@angular/core';
import { FormsModule, NgForm } from "@angular/forms";
import { AngularFireDatabase } from "angularfire2/database";
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
  isLoggedIn: boolean = false;
  courses: any[];
  constructor(public db: AngularFireDatabase) {
    db.list('/Courses').valueChanges().subscribe(courses => {
      this.courses = courses;
      console.log(this.courses);
    });
  }

  login() {
    this.isLoggedIn = !this.isLoggedIn;
  }
  user:any;
  saveData(formData) {
    if (formData.valid) {
      console.log(formData.value);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { HttpModule } from "@angular/http";
import { AppRoutingModule } from './app-routing.module';

import { AngularFireModule } from "angularfire2";
import { AngularFireDatabaseModule } from "angularfire2/database";
import { AngularFireAuthModule } from "angularfire2/auth";

import { AppComponent } from './app.component';

export const firebaseConfig = {
  apiKey: "apikey",
  authDomain: "angular-f5fa9.firebaseapp.com",
  databaseURL: "https://angular-f5fa9.firebaseio.com",
  projectId: "angular-f5fa9",
  storageBucket: "angular-f5fa9.appspot.com",
  messagingSenderId: "592083773091"
};

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AngularFireModule.initializeApp(firebaseConfig),
    AngularFireDatabaseModule,
    AngularFireAuthModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

控制台错误

FirebaseError {
code: "app/bad-app-name", 
message: "Firebase: Illegal App name: '[object Object] (app/bad-app-name).", 
name: "[object Object]", 
ngDebugContext: DebugContext_, 
ngErrorLogger: ƒ, …}
Run Code Online (Sandbox Code Playgroud)

toe*_*oel 0

为了解决这个问题,

第1步:使用以下命令卸载

npm uninstall --save firebase
Run Code Online (Sandbox Code Playgroud)

第 2 步:现在,打开 package.json 文件。在那里,您会发现:

"angularfire2": "^5.0.0-rc.4"
Run Code Online (Sandbox Code Playgroud)

步骤 3:在此行下方添加此行(不带插入符号 (^)):并保存

"firebase": "4.8.0"
Run Code Online (Sandbox Code Playgroud)

第 4 步:现在进行 npm 安装。您的应用程序应该可以运行