【问题标题】:angular fire 2 error when retrieving item from fire base with key使用密钥从火力基地检索项目时出现角火 2 错误
【发布时间】:2017-06-06 21:12:14
【问题描述】:

当我尝试使用这种格式的 items 键从 Firebase 检索项目时,我收到此错误。

getUser(id: string){
  console.log("current user id: " +  id);
  const user = this.af.database.object(`/userData/${id}`);
  this.userFromDb = this.af.database.object(`/userData/${id}`);
  user.subscribe(console.log);
  console.log("object from db: " + this.userFromDb);
  return this.userFromDb;
}

错误:database.refFromURL 失败:第一个参数必须是有效的 Firebase URL,并且路径不能包含“.”、“#”、“$”、“[”或“]”。

【问题讨论】:

  • 请包含来自console.log("current user id: " + id); 的输出 从错误中可以明显看出传递给object() 的路径包含无效字符。
  • 似乎/userData/${id}在查询firebase之前没有解析成插值字符串。

标签: angular typescript firebase ionic-framework angularfire2


【解决方案1】:

如错误消息中所示$ 无效。 Firebase 完全支持类似路径的 URL,所以这应该可以工作:

const user = this.af.database.object('/userData/' + id);

【讨论】:

    猜你喜欢
    • 2016-09-17
    • 1970-01-01
    • 2021-12-18
    • 2021-05-04
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多