firebase .then() 不是函数

firebase .then() is not a function

我正在尝试获取集合中的所有文档。

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


@Injectable({
  providedIn: 'root'
})
export class FirebaseService {

  constructor(public db: AngularFirestore, public router: Router) { }
    getAll() {
     this.db.collection('Completed-Forms').get().then((querySnapshot) => {
       querySnapshot.forEach((doc) => {
         // doc.data() is never undefined for query doc snapshots
         console.log(doc.id, ' => ', doc.data());
      });
    });
  }
}

我的错误:

Uncaught (in promise): TypeError: this.db.collection(...).get(...).then is not a function

TypeError: this.db.collection(...).get(...).then is not a function

有谁知道出了什么问题吗?

您正在使用 AngularFire2,它将文档公开为可观察对象。

如果您想使用常规 JavaScript SDK,请执行

firebase.firestore().collection('Completed-Forms').get().then((querySnapshot) => {

或者(未经测试,但应该根据 TypeScript 声明工作):

this.db.firestore.collection('Completed-Forms').get().then((querySnapshot) => {