我在哪里添加 firebase.initializeApp() 在我的 angular 7 项目中?
问题描述:
我正在尝试将我的 angular 应用程序部署到 firebase 托管,但在控制台中出现以下错误:未捕获的 FirebaseError:firebase.initializeApp 中未提供projectId".
Im trying to deploy my angular app to firebase hosting and I get the following error in console: Uncaught FirebaseError: "projectId" not provided in firebase.initializeApp.
我的 app.module.ts 中有这个:
I have this in my app.module.ts:
export class AppModule {
constructor(private afs: AngularFirestore) {
afs.firestore.settings({
timestampsInSnapshots: true,
});
afs.firestore.enablePersistence();
firebase.initializeApp(environment.firebase);
}
}
我应该在 app.module 中的哪里添加 initializeApp 命令?
Where exactly should I add the initializeApp command in app.module?
答
有很多方法.要在最顶部初始化它,请执行以下操作
There are many ways. To initialize it at the very top, do it as follows
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
firebase.initializeApp(environment.firebase)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }