I've looked at numerous posts but none quite do what I want it to do. I have a table which goes outside the width of the page and for various reasons I need to get it's width.
I used:
@ViewChild('tableToMeasure') elementView: ElementRef;
And then put #tableToMeasure on the table. However this seems to error:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'nativeElement' of undefined
Even though this works on and only on the parent div of the page.
Any ideas? I need to get it's width on both page load and page resize and change another divs width to be the same value.
@Component({
selector: 'selector',
template: `<button #tableToMeasure>Click me</button>`
})
export class FeatureComponent implements AfterViewInit {
@ViewChild('tableToMeasure') elementView;
constructor() {
}
ngAfterViewInit() {
console.log(this.elementView.nativeElement);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With