Accessing the Component Host Element Via Constructor Injection

Photo by Irina Iriser on Unsplash

Update Version

Scenario

Approach

@Component({
selector: 'hello',
...export class HelloComponent{
constructor(private hostElement: ElementRef) {}
ngOnInit() {
const styles = getComputedStyle(this.hostElement.nativeElement);
console.log("Height", styles.height);
console.log("Width", styles.width);
}

Demo

Brought to You By Firefly Semantics