【问题标题】:set Title conditionally (Angular)有条件地设置标题(角度)
【发布时间】:2020-06-25 22:18:01
【问题描述】:

我需要设置title="",只有当我的条件为真时,如果不应该没有title。 所以,只有当property.propertyKey === 'birthday' title 应该得到birthday 值。

<div
  *ngFor="let property of visibleCandidateProperties"
  [title]="property.propertyKey === 'birthday' ? birthday">

  {{candidate[property.propertyKey]}}
</div>

在上面的代码中它不起作用,因为需要添加一些: false 条件。 我该如何重写它? (也许在.ts文件中重写会更好,而不是.html,但仍然不知道该怎么做)

非常感谢您的帮助!

【问题讨论】:

  • 请看我的更新

标签: angular binding title


【解决方案1】:

怎么样?

<div
  *ngFor="let property of visibleCandidateProperties"
  [title]="property.propertyKey === 'birthday' ? birthday : ''">

  {{candidate[property.propertyKey]}}
</div>

【讨论】:

  • 我使用visibleCandidateProperties{{candidate[property.propertyKey]}} 行中显示整个数据列表(不仅仅是生日)。并且仅在propertyKey === 'birthday' 我想将特定值设置为title 的情况下。此过滤器将对此产生影响。
猜你喜欢
  • 2018-04-19
  • 1970-01-01
  • 2014-02-11
  • 2017-02-26
  • 1970-01-01
  • 2020-05-10
  • 1970-01-01
  • 1970-01-01
  • 2021-01-14
相关资源
最近更新 更多