首页 > 解决方案 > 如何在 Angular 的 NgStyle 中应用默认值?

问题描述

我用它来改变元素的背景。

[style.background-color]="condition ? 'red' : 'green'"

但是因为我要使用主题 - 我不知道当前的default背景颜色是什么..

我应该如何重写以上内容以支持任意主题样式?

标签: cssangular

解决方案


在之前设置默认背景[style.background-color]="condition ? 'red' : 'green'"

所以,代码将是 style="background-color:blue" [style.background-color]="condition ? 'red' : 'green'"

这里蓝色是默认的


推荐阅读