如何从 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/