angular - 尝试从 Firebase Firestore 获取集合时,“类型 '{}' 上不存在属性 'map'”
问题描述
我已按照此处的文档从 firestore 获取带有文档 ID 的数据。
import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import 'rxjs/add/operator/map';
@Injectable()
export class UserService {
userCol : AngularFirestoreCollection<UserInter>;
users : Observable<UserInter[]>;
constructor(private afs:AngularFirestore) { }
GetUsers(){
this.userCol = this.afs.collection<UserInter>('users');
this.users = this.userCol.snapshotChanges().pipe(
map(changes =>{
error here-> return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
data.id = a.payload.doc.id;
return data;
})
}))
return this.users;
}
export interface UserInter {
email ?: string,
Firstname ?: string,
Lastname ?: string,
Address ?: string,
}
export interface UserInterid extends UserInter {id ?: string }
当我 ng-serve 我的应用程序时,我收到此错误
类型“{}”上不存在属性“地图”
解决方案
GetUsers(){
this.userCol = this.afs.collection<UserInter>('users');
this.users = this.userCol.stateChanges(['added']).pipe(
map(changes =>{
return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
data.id = a.payload.doc.id;
return data;
})
}))
return this.users;
}
推荐阅读
- sql-server - 从 Azure SQL 数据库调用 API(相对于 SQL Server)
- ios - 按下后退按钮时,SwiftUI 工具栏项目被剪辑
- c# - identityserver4 和 asp net core spa
- c# - 如何根据四个点计算平均地形坡度?
- node.js - 无法从谷歌日历 api 中读取未定义的属性“删除”
- hadoop - Hadoop YARN - 作业消耗的资源超过用户限制因素
- vbscript - VBS 复制和创建一个连续的文件名
- ios - 应用内购买不提示输入电子邮件
- visual-studio-code - 如何在不丢失扩展和设置的情况下移动 VSCode 安装
- javascript - 如何使 onload 在 customize_controls_enqueue_scripts 上下文中运行 WordPress 主题定制器