我想使用Firebase身份验证uid作为Firestore(字符串)的集合名称,为在我的离子Web应用程序上注册的每个用户创建一个单独的集合。 当我这样做时,遇到以下错误:
错误:未捕获(承诺):TypeError:无法读取未定义的属性'onSnapshot'
TypeError:无法读取未定义的属性“ onSnapshot”
而且该集合未在我的Firestore数据库中创建,如何解决此问题
离子代码
// firebase.service.ts
import { Injectable, OnInit } from "@angular/core";
import { AngularFirestore } from "@angular/fire/firestore";
import { AuthenticationService } from "./authentication.service";
import { NavController } from "@ionic/angular";
@Injectable({
providedIn: "root",
})
export class FirebaseService {
collectionName: string;
constructor(
private firestore: AngularFirestore,
private authService: AuthenticationService,
private navCtrl: NavController
) {}
ionViewdidLoad() {
this.authService.userDetails().subscribe((user) => {
console.log(user.uid);
this.collectionName = user.uid;
});
}
ngOnInit() {}
create_student(record) {
return this.firestore.collection(this.collectionName).add(record);
}
read_students() {
return this.firestore.collection(this.collectionName).snapshotChanges();
}
update_student(recordID, record) {
this.firestore.doc(this.collectionName + "/" + recordID).update(record);
}
delete_student(record_id) {
this.firestore.doc(this.collectionName + "/" + record_id).delete();
}
}