You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

报错:Type 'AngularFirestore' 并非泛型类型,寻求解决方法

Fixing 'Type AngularFirestore is not generic' Error

Hey there, let's get this error sorted out for you! The issue here is that you're trying to use AngularFirestore as a generic type, but that's not how it works in angularfire2. Let me break it down and show you the fix:

What's Going Wrong?

AngularFirestore is the core service class for interacting with Firestore in angularfire2—it's not a generic type itself. The generic type you're looking for is AngularFirestoreCollection, which represents a typed collection reference in Firestore.

Step-by-Step Fix

  1. Update Your Imports
    First, add AngularFirestoreCollection to your imports from angularfire2/firestore:

    import { AngularFireAuth } from 'angularfire2/auth';
    import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore'; // Add AngularFirestoreCollection here
    import { Profile } from './../../models/profile';
    
  2. Adjust Your Class Code
    Change the type of profileCollection to AngularFirestoreCollection<Profile>, then use the injected AngularFirestore instance to create the typed collection reference:

    export class LoginPage {
      profileCollection: AngularFirestoreCollection<Profile>;
    
      // Inject the AngularFirestore service in the constructor
      constructor(private afs: AngularFirestore) {
        // Create a typed collection reference (replace 'profiles' with your actual Firestore collection name)
        this.profileCollection = this.afs.collection<Profile>('profiles');
      }
    }
    

Why This Works

When you call afs.collection<Profile>('profiles'), you're telling angularfire2 to treat the documents in the profiles collection as instances of your Profile model. This gives you type safety and autocompletion for the collection's documents, which is exactly what you were aiming for with the generic type.

内容的提问来源于stack exchange,提问作者jrocc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:39:38