html - 如何为匹配给定值的元素设置 id?

标签 html angular angular7

我在 Angular 7 中有以下内容:

<th *ngFor="let day of weekDays"><div>{{day}}</div></th>

但想设置 <th id="today"对于所有weekDays中的单个元素对应/等于 today .

鉴于:

  this.today = "Fri 5/7";

结果应该是:

<th id="today"><div>Fri 5/7</div></th>
<th><div>Sat 6/7</div></th>
<th><div>Sun 7/7</div></th>
<th><div>Mon 8/7</div></th>
<th><div>Tue 9/7</div></th>
<th><div>Wed 10/7</div></th>
<th><div>Thu 11/7</div></th>

我该怎么做?

最佳答案

尝试这样的事情

 <th *ngFor="let day of weekDays" [attr.id]="today==day?'today':null"><div>{{day}}</div></th>

关于html - 如何为匹配给定值的元素设置 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56899942/

相关文章:

javascript - 单击密码字段外部时如何更改密码可见性

jquery - 如何使用 jQuery 在多选中切换选项的选择?

css - 如何垂直对齐显示 :inline (not inline-block) elements in a div?

Angular 4 更新数组推送 View

angular - 如何在 Angular CLI 中为生产构建启用 gzip 压缩

javascript - 有什么办法可以让 JavaScript 可以使用单独程序生成的值吗?

javascript - 转义 Angular 模板表达式以在 Angular HTML 组件模板中显示?

javascript - 为数组中的每个元素创建 html 元素( Angular )

node.js - 不存在 'Access-Control-Allow-Origin' header .. Angular 7 和 Express

unit-testing - 应用测试返回 "NullInjectorError: No provider for Location!"