首页 > 解决方案 > 从 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。

标签: angular

解决方案


使用 ngStyle 怎么样

customeStyle = 
{
  'color': 'red'
}

;

  <p [ngStyle]="customeStyle">asdasd</p>

推荐阅读