【问题标题】:Dynamically change style Url in Angular 2+在 Angular 2+ 中动态更改样式 URL
【发布时间】:2021-08-13 15:24:56
【问题描述】:

我有多个 scss 组件。我想根据选定的主题加载特定的 scss 组件。 例如: 我有 2 个主题:Theme1.component.scss 和 theme2.component.scss,我可以选择一个主题并将其保存在数据库中。据此,我想加载带有所选主题的主页。

【问题讨论】:

标签: angular


【解决方案1】:

无需保留多个样式组件。创建单个样式表像专业人士一样使用它。无处不在

使用定义如下的css全局变量

--btn-color:'something'

您可以直接使用指令或服务对其进行操作。

改变

--btn-color:'something' 相应地应用任何主题

private themeWrapper = document.querySelector("body");

this.themeWrapper.style.setProperty("--btn-color","red");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-10
    • 2019-03-14
    • 2020-02-21
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 2017-05-27
    • 2021-09-06
    相关资源
    最近更新 更多