javascript - 带有 Angular 6 的 Firebase 导入问题?

标签 javascript typescript firebase angular6

我正在使用 google firebase 创建用户注册系统,我正在学习本教程:

User registration system

注意

: 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/

相关文章:

php - 使用 PHP 在 firebase 上创建主题

firebase - 如何在 flutter 中从 firebase 数据构建 Map<DateTime, List>

javascript - 无法将多个文件上传到云端硬盘

javascript - Resitify 的集中错误处理

node.js - 如何使用 TypeScript 在 Electron 中使用 remote.require()

node.js - 类型错误 : fetch is not a function with @azure/ms-rest-nodeauth

javascript - Disqus SSO 不起作用 - Disqus Docs 似乎已被弃用

javascript - Nuxt JS/Vue 中的动态 URL 路径

typescript - 在 TypeScript 和 NestS 中将类转换为类/对象(实体到 DTO)

android - 存储在子集合中的 firestore 数据