我在我的angular 7项目中哪里添加firebase.initializeApp()?
问题描述:
我正在尝试将我的角度应用程序部署到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 { }