报错:Type 'AngularFirestore' 并非泛型类型,寻求解决方法
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
Update Your Imports
First, addAngularFirestoreCollectionto your imports fromangularfire2/firestore:import { AngularFireAuth } from 'angularfire2/auth'; import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore'; // Add AngularFirestoreCollection here import { Profile } from './../../models/profile';Adjust Your Class Code
Change the type ofprofileCollectiontoAngularFirestoreCollection<Profile>, then use the injectedAngularFirestoreinstance 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

