css - Angular2 获取 css 属性

标签 css angular properties

如何从 ElementRef 元素获取 css 属性? 我尝试使用 element.style 但所有属性都是空的。 Renderer 类有 this.renderer.setElementStyle 方法,但没有 this.renderer.getElementStyle 方法。

最佳答案

elementRef 实例有一个 nativeElement 属性,它本身就是一个元素节点,包含人们可能需要的大部分属性。 现代浏览器很好支持的另一种解决方案是

window.getComputedStyle(elementRef.nativeElement)

关于css - Angular2 获取 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40113448/

相关文章:

javascript - 如何使用 <li> 而不是 <div> 使工具提示代码可行?

html - 有序列表两列流

css - ionic ionic 文本换行 : remove elipsis and go to next line for label

css - css 属性 "top"是 javascript 中的字符串还是数字?

css - div边框定位

javascript - 具有视差背景的浏览器和移动问题 (javascript/jquery)

javascript - 使用像谷歌开发者工具这样的代码来跟踪 View ?

javascript - Angular 5 Material Multiple mat-menu

iOS计算器实现困境: how and where to create the calculator stack

c# - 属性(property)已由 'FrameworkElement' 注册