在angular中,如何使用括号添加class?
In angular, how to add a class using the brackets?
是否可以创建如下所示的内容?
<div *ngFor="let post of posts">
<p class="quote {{post.color}}-quote">
{{ post.content }}
<span class="author">Anatoly Weinstein, Founder of Theora</span>
</p>
</div>
重要的一行:class="quote {{post.color}}-quote"
我已经看到 个问题,但我不想使用布尔值并对每个元素进行硬编码。
没有特殊原因要使用带括号的模板绑定,这个是可以做到的
使用 ngClass
指令:
<p class="quote" [ngClass]="[post.color+'-quote']">
是否可以创建如下所示的内容?
<div *ngFor="let post of posts">
<p class="quote {{post.color}}-quote">
{{ post.content }}
<span class="author">Anatoly Weinstein, Founder of Theora</span>
</p>
</div>
重要的一行:class="quote {{post.color}}-quote"
我已经看到
没有特殊原因要使用带括号的模板绑定,这个是可以做到的
使用 ngClass
指令:
<p class="quote" [ngClass]="[post.color+'-quote']">