angular - 将变量传递给firestore where查询(Angular)
问题描述
我正在尝试查询计划集合,其中文档中的字段 = 用户 ID,但我收到此错误:“函数 Query.where() 需要有效的第三个参数,但它未定义。”
userId;
uid;
sched: Observable<ScheduleModel[]>;
ngOnInit()
ngOnInit() {
this.userId = this.afAuth.authState.subscribe(user => {
this.uid = user.uid;
});
this.getSched();
}
getSched() {
this.sched = this.afs.collectionGroup<ScheduleModel>('schedule', ref => ref.where('uid', '==', this.uid)).valueChanges();
}
查询中的 this.uid 给我带来了麻烦,但是:
解决方案
尝试这个
ngOnInit() {
let self = this;
this.userId = this.afAuth.authState.subscribe(user => {
self.uid = user.uid;
});
this.getSched();
}
this
在您this.uid
的范围内与您使用的范围不同{{uid}}
推荐阅读
- javascript - 用于阻止特定页面元素加载的浏览器扩展
- sql - Postgres - 模式删除后恢复/维护权限
- swiftui - SwiftUI 更改内联 navigationBarTitleDisplayMode 的导航栏背景颜色
- flutter - 如何让 Flutter 对话框消失?
- sql - 通过分组获取用户每月的最新访问日期,即使它为空
- swagger - OpenAPI v3 / Swagger - 调用函数并向其发送 json 字典
- javascript - Javascript 使用 For 循环为 false
- java - 为什么当我尝试转换我的 DTO 时出现 StackOverFlow
- r - 带有附加线的R plotly条形图不起作用
- postgresql - 如何使用外部服务器配置 Kubernetes?