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

标签 angular

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

::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/

相关文章:

node.js - Angular 通用 |火力管理|代码 : 'app/invalid-credential' |socket hang up on

angular - 由于 ngIf,保持隐藏组件的引用

angular - 使用 tomcat 的 Angular CORS

css - 设置背景图片会破坏提交按钮

angular - ng2-pdf-viewer CORS 问题

javascript - 如何取消正在进行的 http 调用解析或拒绝 Angular 组件的 onDestroy

angular - 垫表根据条件显示行

typescript - 从(服务器发送的)EventSource 创建一个 RxJS Observable

css - Angular Material2 md-checkbox边框颜色

angular - 如何向 DialogFlow 添加自定义负载