我正在使用 google firebase 创建用户注册系统,我正在学习本教程:
注意
: am using this version "firebase": "^5.5.6",
当我运行我的应用程序时,出现以下错误:
ERROR in src/app/login/login.component.ts(2,10): error TS2305: Module '"C:/Users/jelly/projects/profile/node_modules/angularfire2/index"' has no exported member 'AngularFire'.
src/app/login/login.component.ts(3,28): error TS2305: Module '"C:/Users/jelly/projects/profile/node_modules/angularfire2/firestore/index"' has no exported member 'AuthProviders'.
src/app/login/login.component.ts(3,43): error TS2305: Module '"C:/Users/jelly/projects/profile/node_modules/angularfire2/firestore/index"' has no exported member 'AuthMethods'.
这是 app.modul.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule, JsonpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { UserProfileComponent } from './user-profile/user-profile.component';
import {HttpClientModule} from '@angular/common/http';
import { UserService } from './service/user.service';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { MomentModule } from 'ngx-moment';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { LoginComponent } from './login/login.component';
import { EmailComponent } from './email/email.component';
import { SignupComponent } from './signup/signup.component';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFireDatabaseModule} from 'angularfire2/database';
const firebaseConfig = {
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: ''
};
@NgModule({
declarations: [
AppComponent,
UserProfileComponent,
LoginComponent,
EmailComponent,
SignupComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgbModule,
BrowserModule,
MomentModule,
AppRoutingModule,
BrowserAnimationsModule,
AngularFireAuthModule,
BrowserModule,
AngularFirestoreModule,
AngularFireModule.initializeApp(firebaseConfig),
AngularFireDatabaseModule,
HttpModule,
FormsModule,
HttpClientModule,
ReactiveFormsModule,
RouterModule,
AppRoutingModule,
],
providers: [UserService],
bootstrap: [AppComponent]
})
export class AppModule { }
这里是登录组件其他组件就空
import { Component, OnInit } from '@angular/core';
import { AngularFire, } from 'angularfire2';
import { AngularFirestore, AuthProviders, AuthMethods, AngularFirestoreCollection, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Router } from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
// declare empyt array to hold error data
error: any;
constructor(public af: AngularFire, private router: Router) {
// fucntion to check user authentication
this.af.auth.subscribe(auth => {
if (auth) {
this.router.navigateByUrl('/members');
}
});
}
// function to login in facebook
loginFb() {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup,
}).then(
(success) => {
this.router.navigate(['/members']);
}).catch(
(err) => {
this.error = this.error;
});
}
// function to login with google
loginGoogle() {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup,
}).then(
(success) => {
this.router.navigate(['/members']);
}).catch(
(err) => {
this.error = this.error;
});
}
ngOnInit() {
}
}
我已经使用了堆栈溢出中的几乎所有解决方案,但没有任何效果,我现在要放弃了,我没有看到任何好的文档让傻瓜明白到底发生了什么:(
我需要更改什么才能消除此错误?请帮忙
最佳答案
教程是从 2017 年 1 月 17 日开始的,如果你运行 npm install angularfire2 firebase --save
你将安装最新版本的 firebase,这不是一个教程所基于的,看这里是similar post on this problem
因此您必须降级您用于此项目的 firebase 版本或升级导入以便它们指向正确的文件,您可以在其中找到您需要的类
关于javascript - 带有 Angular 6 的 Firebase 导入问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082831/