@Angular/fire:错误 FirebaseError:预计 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore

问题描述 投票:0回答:1

尝试读取 firestore 集合时出现错误。我已经检查了 stackoverflow 上可用的解决方案,但仍然无法解决此问题。

我已经使用 AngularFire Cloud Firestore 文档实现了代码。 https://github.com/angular/angularfire/blob/master/docs/firestore.md#cloud-firestore

错误 FirebaseError:预计 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore main.ts:13 FirebaseError:预计 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore

“@角度/核心”:“^16.2.0”, “@角度/火”:“^7.6.1”, “firebase”:“^10.3.1”,

app.module.ts

imports: [
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAnalytics(() => getAnalytics()),
    provideAuth(() => getAuth()),
    provideDatabase(() => getDatabase()),
    provideFirestore(() => getFirestore()),
    provideFunctions(() => getFunctions()),
    provideMessaging(() => getMessaging()),
    providePerformance(() => getPerformance()),
    provideRemoteConfig(() => getRemoteConfig()),
    provideStorage(() => getStorage())
  ]

auth.service.ts

import { Inject, Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { Auth, authState, signInWithEmailAndPassword, 
    createUserWithEmailAndPassword, onAuthStateChanged, 
    signOut, GoogleAuthProvider,
    user} from "@angular/fire/auth";
import { Firestore, collectionData, collection, getFirestore, getDocs  } from "@angular/fire/firestore";
import { AngularFireAuth,  } from '@angular/fire/compat/auth';
import { Router } from '@angular/router';

@Injectable({ providedIn: 'root' })
export class AuthService {
    userData: any; 
    UsersCollection: any;
    UsersData: any; 

    constructor( 
        private auth: Auth,
        private firestore: Firestore,
        private afAuth: AngularFireAuth,
        private router: Router
        ) {
            const itemCollection = collection(this.firestore, 'Classes');
    }
}

控制台日志输出

angular angularfire
1个回答
0
投票

更新 package.json 文件中“@angular/fire”、“firebase”和“rxfire”的礼仪版本后,此问题已得到解决

目前,Firebase v10 与最新的 AngularFire 稳定版本不兼容 – 有一个新的 AngularFire 版本即将推出,它将支持最新的 v10

https://github.com/angular/angularfire/issues/3435

© www.soinside.com 2019 - 2024. All rights reserved.