Angular Firebase、角4根模块和;功能模块-";没有Firebase应用程序';[默认]';已创建-调用Firebase App.initializeApp();
在我的应用程序中,我有一个根模块(app.module.ts)和一个功能模块(contact.module.ts)。我使用AngularFireModule作为根模块中的设置(如下所示),出于某种原因,我得到了这个错误:“error_handler.js:47原始异常:没有创建Firebase应用程序“[DEFAULT]”-调用Firebase App.initializeApp()。”我想知道为什么 应用程序模块.tsAngular Firebase、角4根模块和;功能模块-";没有Firebase应用程序';[默认]';已创建-调用Firebase App.initializeApp();,angular,typescript,firebase,firebase-storage,angularfire2,Angular,Typescript,Firebase,Firebase Storage,Angularfire2,在我的应用程序中,我有一个根模块(app.module.ts)和一个功能模块(contact.module.ts)。我使用AngularFireModule作为根模块中的设置(如下所示),出于某种原因,我得到了这个错误:“error_handler.js:47原始异常:没有创建Firebase应用程序“[DEFAULT]”-调用Firebase App.initializeApp()。”我想知道为什么 应用程序模块.ts import { NgModule } from '@angular/co
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
import * as firebase from 'firebase';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
import { environment} from '../environments/environment';
import { AppComponent } from './app.component';
import { ContactModule} from "./customer/customer.module";
import { AuthenticationService } from "./authentication/authentication.service";
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ReactiveFormsModule,
HttpModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule,
AngularFireAuthModule,
ContactModule
],
providers: [AuthenticationService],
bootstrap: [AppComponent]
})
export class AppModule { }
环境科技
export const environment = {
production: false,
firebase = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
}
}
contact.ts(v1)
出于某种原因,我再次遇到这个错误:“error_handler.js:47原始异常:没有创建Firebase应用程序“[DEFAULT]”-调用Firebase应用程序.initializeApp()
我试图将firebase配置对象从environment.ts文件移动到app.module.ts文件,但没有解决错误。仅当我在contact.ts文件中导入firebase时,它才起作用:
contact.ts(v2)
这可能与功能模块的实现有关contact.module.ts。正如您所知,我还尝试将firebase配置移动到contact.module.ts但错误仍然存在。因此,我想知道如何在应用程序范围内设置firebase配置,使其运行,而不必从contact.ts文件初始化firebase
任何帮助都将不胜感激。
谢谢我看到你初始化了AngularFire,但你没有初始化Firebase。@StevenScott谢谢你的及时回答。据我所知,AngularFire在app.module的导入中进行初始化:
AngularFireModule.initializeApp(environment.firebase)
我正在努力解决这个问题。你能告诉我在这种情况下如何初始化firebase吗?!我想你基本上需要做同样的事情,只是使用Firebase引用,而不是AngularFire对象。@StevenScott好吧,我试过了,但仍然出现另一个错误。我不确定,因为我没有使用它,但如果它按照你的指示工作,那么你可能需要将它添加到每个模块中。
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import * as firebase from 'firebase';
@Component({
//...
})
export class ContactComponent implements OnInit {
//...
constructor(private _router: Router) {
// Get a reference to the storage service
const storageSvc = firebase.storage();
// Create a storage reference from our storage service
const storageRef = storageSvc.ref();
const picStorageRef = storageRef.child('contacts/pic1.jpg');
picStorageRef.getDownloadURL().then(url => this.picURL = url);
}
ngOnInit() {}
}
//...
import * as firebase from 'firebase';
import { environment } from '../../environments/environment';
//...
export class ContactComponent implements OnInit {
//...
constructor(//...) {
firebase.initializeApp(environment.firebase);
// Get a reference to the storage service
const storageSvc = firebase.storage();
// Create a storage reference from our storage service
const storageRef = storageSvc.ref();
const picStorageRef = storageRef.child('contacts/pic1.jpg');
picStorageRef.getDownloadURL().then(url => this.picURL = url);
}
}