Ben
Ben

Reputation: 4110

Angular2 get css property

How can I get css properties from a ElementRef element? I've tried to use element.style but all the properties are empty. The Renderer class has this.renderer.setElementStyle method but there is no this.renderer.getElementStyle method.

Upvotes: 7

Views: 7208

Answers (1)

Yaroslav Grishajev
Yaroslav Grishajev

Reputation: 2137

elementRef instance has a nativeElement property which is an element node itself and contains most of the properties one may need. Another solution which is well supported by modern browsers is

window.getComputedStyle(elementRef.nativeElement)

Upvotes: 8

Related Questions