问题描述
我想要一个项目,该项目使用AngularFire初始化Firebase .但是,在整个开发过程中,我并没有使用AngularFire的很多功能.我总是在每个服务处导入firebase/app
并使用相应的功能,例如firebase.auth()
或firebase.database()
.
I want had a project that initialize firebase by using AngularFire. However, during the entire development I didn't use much function from AngularFire. I always import the firebase/app
at every services and use the respective function like firebase.auth()
or firebase.database()
.
以这种经验,我想在没有AngularFire的情况下初始化firebase,因为我没有使用AngularFire方法.
With that experience, I would like to initialize the firebase without AngularFire since I am not using the AngularFire methods.
现在出现的问题是我找不到任何教我如何初始化Firebase的资源,当然,在app.module.ts
处导入Firebase时我看到错误.
Now come with my problem is I can't find any source to teach me how to initialize the firebase, and of course I am seeing error during importing the firebase at app.module.ts
.
下面是我的代码:
使用以下命令安装Firebase:npm i firebase
Install the firebase by using: npm i firebase
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import * as firebase from 'firebase';
import { environment } from '../environments/environment'; //API key is imported
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
firebase.initializeApp(environment.firebase) //here shows the error
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
在firebase.initializeApp(environment.firebase)
行,它显示错误:
Type 'App' is not assignable to type 'any[] | Type<any> |
ModuleWithProviders<any>'.
Type 'App' is not assignable to type 'ModuleWithProviders<any>'.
Property 'ngModule' is missing in type 'App'.
谢谢.
推荐答案
我会说您遇到此错误,因为firebase.initializeApp(environment.firebase)
不是Angular Module.
I would say you are having this error because firebase.initializeApp(environment.firebase)
is not Angular Module.
我建议您在其中一项服务中进行此初始化,或者为此创建服务.
I would suggest that you do this initialisation in one of your services or create a service for that effect.
@Injectable({
providedIn: 'root'
})
export class FirebaseService {
constructor() {
firebase.initializeApp(environment.firebase)
}
}
这篇关于在没有angularfire的情况下以角度6初始化firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!