css - 在角度,如何使用方括号添加一个类?
问题描述
是否可以创建类似下面的内容?
<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']">
推荐阅读
- node.js - 当我们在nodejs中使用mongoose从mongodb中选择复杂对象时,有没有办法重命名路径?
- javascript - 如何在 AWS lambda 代码中为 S3 指定目录、权限和创建子目录?
- c++ - 如何向 Dobot 发送持续指示?
- c# - 如何同时运行控制台和表单?C#
- java - `Future` 任务完成后检查字段是否安全?
- lodash - 查找数组索引失败
- java - Java 电源模拟单元测试具有 Thread.Sleep 的方法
- python-3.x - Apache-Airflow UI 页面大小不会改变
- ruby-on-rails - Rails ActiveAdmin:路由到 /admin/admin/my_resource
- gcc - Make:我们可以在 GNUmakefile 中将目录作为目标吗