错误TypeError:app.auth不是函数

时间:2019-10-30 16:43:15

标签: angular typescript firebase firebase-authentication

https://stackblitz.com/edit/angular-qxwzto?file=src%2Fapp%2Fbs-navbar%2Fbs-navbar.component.ts

在我编写此代码时在stackblitz中

import { AngularFireAuth } from 'angularfire2/auth';
import { Component, OnInit } from '@angular/core';  

@Component({
  selector: 'bs-navbar',
  templateUrl: './bs-navbar.component.html',
  styleUrls: ['./bs-navbar.component.css']
})
export class BsNavbarComponent {


  constructor(private afAuth: AngularFireAuth ) {
    afAuth.authState.subscribe(x=> console.log(x));
  }

  logout() {
    this.afAuth.auth.signOut();
  }

}

我收到此错误

  

错误TypeError:app.auth不是函数

默认的Firebase版本为firebase@6.6.2

我尝试安装firebase@4.6.0,但是随后出现新错误

  

ERROR FirebaseError {{code:“ app / bad-app-name”,消息:“ Firebase:   非法的应用程序名称:“ [对象对象](应用程序/坏应用程序名称)。”,名称:   “ [对象对象]”

=======================================

  

TypeError:app.firestore不是函数

https://stackblitz.com/edit/hamza-fruit-shop?file=src%2Fapp%2Fservices%2Fgoods.service.ts

goods.service.ts

import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';


@Injectable({
    providedIn: 'root'
})
export class GoodsService {
    constructor(private fs: AngularFirestore) {}
    getAllGoods() {
        return this.fs.collection('goods').valueChanges();
    }
}

https://stackblitz.com/edit/hamza-fruit-shop?file=src%2Fapp%2Fcomponents%2Fhome%2Fhome.component.ts

home.component.ts

import { GoodsService } from './../../services/goods.service';
import { Component, OnInit } from '@angular/core';
import { Good } from './../../interfaces/good.interface';

@Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: [ './home.component.css' ]
})
export class HomeComponent implements OnInit {
    goods: Good[] = [];

    constructor(private gs: GoodsService) {}

    ngOnInit() {
        this.gs.getAllGoods().subscribe((data) => (this.goods = data));
    }

    addToCart(index) {
        console.log('added', this.goods[index]);
    }
}

我得到了错误

  

TypeError:app.firestore不是函数

0 个答案:

没有答案