我正在升级到Angular v5和firestore,我在从firestore数据中提取字段时遇到很多问题 .
我不想使用angularfire2,因为当Angular 4发布时我遇到了问题 .
大约10天前,我花了很长时间搞清楚如何从快照中获取数据 . 最后我得到了下面的代码来做到这一点 . 不幸的是“doc.data()['languageName'];”不适用于“get” .
querySnapshot.forEach(function (doc) {
let name = doc.data()['languageName'];
lang.push(name);
});
});
在这一整天工作后,我决定寻求帮助 . 我的最新尝试如下 .
firebase.auth().signInWithEmailAndPassword(email, password)
.then(staff => {
if (staff.emailVerified) {
this.result = this.db.collection("staff").doc(staff.uid).get()
.then(function(staffDb) { // staff.uid works
if (staffDb.exists) { // <-- Works to here
this.sid = staffDb.data.sid; // nor staff.sid
this.staff2memoryService.set(staffDb.data());
this.staff = this.db.collection("staff").
doc(this.sid).get()
.then(result => {
if (this.sid) {
this.staff2memoryService.set(result);
} else {
console.log('Not exist');
}
当我做一个console.log时,我想要的所有数据都存在,但我无法得到它 . firebase文档显示了如何使用console.log访问字段,但这没有帮助,因为console.log似乎自动提取/映射字段 .
1 回答
我昨天尝试使用“this.data”但未成功,但以下工作 .
有时最好是睡一个问题,昨天几分钟就是几个小时 . 我渐渐老了!