Is there a way to retrieve the width of an element with a dynamic width using Angular 2? I can easily accomplish this with pure javascript, but not through Angular 2.
constructor(private element: ElementRef) {
// ....
Obtaining the width
let width = this.element.nativeElement.offsetWidth;
console.log('js offset width', document.getElementById('foobar').offsetWidth);
console.log('angular2 offset width', width);
Getting the width through vanilla JavaScript works as expected:
document.getElementById('foobar').offsetWidth
However, when trying to get the width in Angular 2, it always returns 0. How can I access the offset width using Angular's ElementRef instead?