javascript - 如何从 Angular 组件中读取 :root 中的 CSS 变量?
问题描述
我试着这样做,像这样:
this.elementRef.nativeElement.style['--config-use-images'];
和
document.documentElement.style.getPropertyValue('--config-use-images');
两者都没有工作。变量肯定存在。我可以在下的开发工具中看到它:root
。当我在控制台中记录第一个时,我得到一个未定义的,第二个是一个空字符串。
解决方案
尝试这个:
getComputedStyle(document.documentElement).getPropertyValue('--config-use-images')
或者
getComputedStyle(this.elementRef.nativeElement).getPropertyValue('--config-use-images')
推荐阅读
- java - KRUSKAL 最小生成树
- angular - 未捕获的错误:模板解析错误:意外的结束标记“表单”。当标签已被另一个标签关闭时,可能会发生这种情况
- python-3.x - 图表是颠倒的
- r - 性能问题 - 在列表中分配多个大矩阵
- quickbooks - quickbook app/tax/home 重定向到 /app/salestax?showExistingUI=true
- c - Linux 编译出错:缺少分隔符
- python - 为简单的全连接神经网络解决 Keras 和 scikit-learn 之间的差异
- java - JLS - 等待集合 - 它在哪里?
- javascript - 在 jquery 中使用两个下拉菜单?
- java - 为什么我在 JavaFX 中的第二个场景没有出现?