在我的Angular应用中,Firebase会返回一个错误,显示bad-app-name
为代码。
我在角应用程序中使用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);
}
}
}
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 { }
控制台错误
FirebaseError {
code: "app/bad-app-name",
message: "Firebase: Illegal App name: '[object Object] (app/bad-app-name).",
name: "[object Object]",
ngDebugContext: DebugContext_,
ngErrorLogger: ƒ, …}
答案 0 :(得分:3)
对我有用的解决方案:
npm uninstall --save firebase angularfire2
然后
npm install angularfire2 firebase --save
答案 1 :(得分:1)
我只是遇到同样的错误。我通过确保
"@firebase/app": "^0.3.3",
依赖关系是最新的。
答案 2 :(得分:0)
要解决此问题,
步骤1:使用以下命令卸载
npm uninstall --save firebase
第2步:现在,打开你的package.json文件。在那里,你会发现:
"angularfire2": "^5.0.0-rc.4"
第3步:在此行下方,添加一行(不带Caret(^)符号):并保存
"firebase": "4.8.0"
第4步:现在进行npm安装。您的应用应该可以使用
答案 3 :(得分:0)
"angularfire2": "^5.0.0-rc.7",
"firebase": "4.12.1"