angular6 angularfire未初始化

时间:2018-10-26 07:11:42

标签: angular firebase angularfire2

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { AngularFireModule } from 'angularfire2'
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { environment } from '../../environments/environment';
import { MatButtonModule, MatCheckboxModule, MatInputModule } from '@angular/material';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { LoginRoutingModule } from './login-routing.module';
import { LoginComponent } from './login.component';


@NgModule({
    imports: [
        CommonModule,
        LoginRoutingModule,
        MatInputModule,
        MatCheckboxModule,
        MatButtonModule,
        FlexLayoutModule,
        FormsModule, 
        ReactiveFormsModule,
        AngularFireModule.initializeApp(environment.firebase),
        AngularFirestoreModule,
        AngularFireAuthModule, 
    ],
    declarations: [LoginComponent]
})

export class LoginModule {}

上面是我的登录模块的代码,它在控制台上引发错误,未初始化默认应用程序

  

FirebaseError {code:“ app / no-app”,消息:“ Firebase:No Firebase App   '[DEFAULT]'已创建...-调用Firebase App.initializeApp()   (app / no-app)。“,名称:” [DEFAULT]“,堆栈:” [DEFAULT]:Firebase:否   Firebase应用'[DEFAULT]'h…ontext   (http://localhost:4200/vendor.js:56563:25)“}

如何解决?

1 个答案:

答案 0 :(得分:0)

根据文档,您需要在AngularfireModule()范围内初始化app.module.ts应用程序。然后,您可以在子模块中定义要导入的模块。

app.module.ts中添加它们,并从login.module.ts中删除它们

AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule,
AngularFireAuthModule, 

请参阅official docs.