我在 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/