I am unsure why you access your div through ViewChild
and document
query. I would advice you to stick with Angular tools rather than mixing up with raw JS queries.
The likely reason why you can't access style is because you are trying to access style of an object which does not reflect your div but something else. I could be more precise if you share your component.ts
code, but I would think your ViewChild
is typed as ElementRef
. If so, you are one level of representation higher than the actual dom reference. You need to access nativeElement
of your ElementRef
and you should be able to retrieve its style.
If you retrieve a different type of ViewChild
- such as any Material specified types - you will need to access first ElementRef
from your component reference, then nativeElement
and finally its style.
html
<mat-card #fancyCard>Testing</mat-card>
ts
@ViewChild('fancyCard', {static: true}) myCard: MatCard;
[...]
this.myCard._elementRef.nativeElement.style;
Please note that you can specify options in ViewChild
annotation such as read: ElementRef
to access right away to ElementRef
(if you don't want to manipulate the component itself but rather just have a reference on its dom element).
If you feel like this answer is not fitting your need, please provide more context / information about your code, I will edit my answer.