我正在跟踪集合上的[消]火源文档,并且无法理解为什么在尝试使用文档id检索文档集合时,我的代码不能按照文档的工作方式工作。
我的IDE显示了以下错误:
属性'map‘在'Action< DocumentSnapshot< any>>’类型上不存在。
关于下列代码:
this.userDocRef = this.afs.doc<any>(`users/${user.uid}`);
this.userDoc$ = this.userDocRef.snapshotChanges().pipe(
map(actions => {
return actions.map(a => { // error throws here
const data = a.payload.doc.data() as any;
const id = a.payload.doc.id;
return { id, ...data };
})
})
)当我运行这段代码时,我会得到以下错误:
错误TypeError: actions.map不是一个函数
如何重构它以使其正常工作?
"firebase": "^5.0.4"
"@angular/core": "^6.1.0"
"angularfire2": "^5.0.0-rc.10"发布于 2018-08-14 13:35:59
映射代码是错误的:
map(actions => {
return actions.map(a => { // error throws here
const data = a.payload.doc.data() as any;
const id = a.payload.doc.id;
return { id, ...data };
})
})这用于映射集合。您不是在监视一个集合,而是一个文档
尝试:
this.userDoc$ = this.userDocRef.snapshotChanges()
.pipe(
map(action => {
const data = action.payload.data();
const id = action.payload.id;
return { id, ...data };
})
);https://stackoverflow.com/questions/51842530
复制相似问题