Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 590
Ben Avatar asked Oct 18 '16 16:10

Ben


People also ask

What is Ngdeep?

::ng-deep is what's called a shadow-piercing descendant combinator. It works because it is able to pierce the shadow DOM. Using ::ng-deep to override a child components styles will achieve the desired result but with unintended side effects.


1 Answers

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)
like image 115
Yaroslav Grishajev Avatar answered Nov 12 '22 07:11

Yaroslav Grishajev