【发布时间】:2018-06-02 22:07:10
【问题描述】:
我正在升级到 Angular v5 和 firestore,我在从 firestore 数据中提取字段时遇到了很多问题。
我不想使用 angularfire2,因为我在 Angular 4 发布时遇到了问题。
大约 10 天前,我花了很长时间研究如何从快照中获取数据。最后我得到了下面的代码来做到这一点。不幸的是“doc.data()['languageName'];”不适用于“获取”。
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 似乎会自动提取/映射字段。
【问题讨论】:
标签: javascript angular google-cloud-firestore