gpt4 book ai didi

angular - 如何使用 ng-deep 处理动态数据

转载 作者:行者123 更新时间:2023-12-02 02:58:52 24 4
gpt4 key购买 nike

我需要为给定类动态定义字体大小,但它们的值是从服务器获取的。静态看起来像这样:

::ng-deep .text-huge {
font-size: 2.8em;
}

我如何转换它以便分配的值是动态的?

::ng-deep .text-huge {
font-size: data.fontSize;
}

谢谢你的帮助

最佳答案

You can't assign CSS variable's value from the TS.

Set sass variable value in Angular 7

你可以做的是在你的项目中使用 CSS 变量,这些变量被 TS 文件修改了一些值:

CSS:

::root {
--some-var: #fff;
}

.your-class {
color: var(--some-var);
}

在 ts 中:

// Assuimg that new value is an HEX color without `#`
public changeSomeVar(newValue: string): void {
document.documentElement.style.setProperty('--some-var', #${newValue});
}

关于angular - 如何使用 ng-deep 处理动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60437024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com