angular - 从 component.ts 在 Angular 7 中添加内联 css
问题描述
我的 Angular 7 应用程序,我可以使用它从左到右和从右到左滚动查看产品。 滚动
每个图像在单击时都有按钮,我在 typescript (component.ts) 中应用了新的 CSS,如下所示。
this.appendToSimilar.nativeElement.appendChild(document.getElementById(item.imageId).cloneNode()).classList.add('similar-floating');
在这里,我需要传递内联 css 而不是类名。
期待
this.appendToSimilar.nativeElement.appendChild(document.getElementById(item.imageId).cloneNode()).classList.add('.cssClassName{width:50px, hight: 100px}');
我确信 .add 可以用来添加类名。任何人都可以帮我为上述场景添加内联 css。
解决方案
使用 ngStyle 怎么样
customeStyle =
{
'color': 'red'
}
;
<p [ngStyle]="customeStyle">asdasd</p>
推荐阅读
- visual-studio - Visual Studio 针对 dll 文件的错误位置
- c# - 如何阻止实体框架继续从数据库中记录?
- swift - 下载音频文件
- c++ - 查找具有 N 个元素的数组的最小值和最大值
- c++ - 在处理任何字符大小的模板中使用字符串文字
- angular - 使用 mat-optgroup 将全选按钮添加到 mat-select
- javascript - 单击按钮时在表格中的整行中关闭禁用
- android - IllegalAccessException:无法访问 com.android.build.gradle.tasks.ManifestProcessorTask 类的成员
- postgresql - postgres 中的 REGEXP_COUNT
- c++ - C++:将值分配给原始数据类型(例如 bool)是原子操作吗?