我在哪里添加 firebase.initializeApp() 在我的 angular 7 项目中? [英] Where do I add firebase.initializeApp() in my angular 7 project?

查看:25
本文介绍了我在哪里添加 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 { }

这篇关于我在哪里添加 firebase.initializeApp() 在我的 angular 7 项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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