我刚刚使用angular cli开始了一个新项目。
我已经在环境火灾中设置了我的firebase配置。
我在我的应用模块中初始化应用,但是我收到以下错误:
Firebase:没有创建Firebase应用程序'[默认]' - 调用Firebase App.initializeApp()(app / no-app)。
应用模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// AngularFire and Firestore
import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';
// Routing
import { AppRouting } from './routing/app-routing';
// Environment
import { environment } from '../environments/environment';
// Components
import { LoginModule } from './login/login.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule,
AppRouting,
LoginModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我的登录组件显示,但是当我尝试调用'createUserWithEmailAndPassword'时,我收到错误。
登录组件
import * as firebase from 'firebase';
...
createAccount(){
firebase.auth().createUserWithEmailAndPassword(this.email, this.password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode + ' / ' + errorMessage);
// ...
});
}
我在之前的项目中使用了相同的设置,该项目在较旧的cli版本上运行。知道这可能是什么吗?
答案 0 :(得分:2)
在您的登录组件中,您没有使用已初始化的angularfire2。您没有初始化标准的Firebase sdk
https://github.com/angular/angularfire2/blob/master/docs/auth/getting-started.md