【发布时间】:2019-03-19 03:10:32
【问题描述】:
所以我正在制作一个 Angular 应用程序,并且有一次我想存储一个用户变量(我从对 Firestore Cloud 的异步调用中获得),该变量确实已设置(使用 console.log() 检查)但是当我切换页面并尝试在 Firestore 上加载该用户的食谱时,它说我的用户变量未定义。
有没有更好的方法来做到这一点?
谢谢
编辑:代码
tryConnect(email: string, password: string) {
// u = array of users
this.usersWithId.subscribe(u => {
for (const a of u) {
console.log(a);
if (a.email === email && a.password === password) {
this.connectedUser = a;
console.log(this.connectedUser);
break;
}
}
});
}
addRecipe(recipe: Recipe) {
console.log(this.connectedUser);
this.db.collection('/recipes').add({
name: recipe.name,
description: recipe.description,
meal: recipe.meal,
steps: recipe.steps,
servings: recipe.servings,
cuisine: recipe.cuisine,
userID: this.connectedUser.userID,
ingredients: recipe.ingredients
});
【问题讨论】:
-
你能发布一些你的代码吗?
-
@Brandon 我现在不在家,但我会的!
标签: angular typescript google-cloud-firestore angular6 webstorm