有条件地设置标题(角度)

时间:2020-06-25 22:18:01

标签: angular binding title

仅当我的条件为true时,才需要设置title="",如果根本不存在title,则需要设置property.propertyKey === 'birthday'。 因此,只有title的{​​{1}}应该获得birthday的值。

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

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

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

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

那怎么样?

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

  {{candidate[property.propertyKey]}}
</div>
相关问题