javascript - 在 Angular 5 HTML 中将变量添加到对象路径中

标签 javascript html angular

我在 firebase 上有一个对象,其中有一系列针对特定文档上每个用户的对象。每个用户的对象初始对象键是他们的 UID。我正在尝试检查用户是否有对象。问题是动态传递 userId 找不到正确的路径:

this.userId = this._auth.currentUserId;

<p *ngIf="tenancy_offer.application.members.userId">UserId exists</p>

这将返回 null,因为它正在查找 userId 的键而不是用户的实际 ID。那么,如何将变量作为对象路径的一部分动态传递?

这是 firestore 中的对象: enter image description here

最佳答案

如果 userId 在 mebers objetc 中是散列(如 onq9wawO7...)然后尝试

<p *ngIf="tenancy_offer.application.members[userId]">UserId exists</p>

关于javascript - 在 Angular 5 HTML 中将变量添加到对象路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54551920/

相关文章:

javascript - 从外部javascript文件调用html中的函数

angular - 为什么我不需要导出/导入 TypeScript 接口(interface)?

javascript - 在 couchdb reduce 中使用 "eval"- 这有多危险?

javascript - ng-model 到我的服务器上的异步 xhr get/set 字段

html - Material CSS 表 Accordion

angular - 跨源请求过滤掉了我的大部分 API 响应 header

angular - angular 2 中的 behaviorSubject,它是如何工作的以及如何使用它

javascript - Fabricjs Canvas 有时会错误地加载对象?

javascript - 在node.js REPL 中使用SetInterval?

html - 根据父 Div 设置 Div 高度