Angula 11 // REMARK THIS HAPPENS WITH ALL THE OFFSETS BUT GET THE ID PER EXAMPLE WORKS
So we have a few @Viewchilds
of ElementRefs
that we want to get the offsetWidth
.
To do that we have the following code:
// container is the REF that has the HTML --> #container
@ViewChild('container') containerRef: ElementRef;
...
...
ngAfterViewInit(): void {
const containerOffset: number = this.containerRef.nativeElement.offsetWidth;
const containerOffset1: number = (this.containerRef.nativeElement as HTMLElement).offsetWidth;
}
The problem is that the offsets that we get are 0.
But if we do a console.log(this.containerRef)
it shows perfectly the nativeElement inside and you can see that the offset is different than 0.
Someone can help here please ?
( If possible a solution without using document.querySelector.....)