I have a very small basic angular (14) SPA with a couple of routes. I'm using @ViewChild to get the coordinates of a particular element:
@ViewChild('testElement', { static: true }) testElement!: ElementRef<HTMLDivElement>;
and then
ngAfterViewInit(): void {
var position = this.fadeInText.nativeElement.getBoundingClientRect();
var y = position.top; // (etc)
}
What I've noticed is that I get incorrect y values if I return to the route after going to another route.
However, if I check the positions again in ngAfterViewChecked after it has fired at least once before, I get the correct position values.
Is there a better way to handle this? I can't seem to find any other documentation on this issue.
Many thanks!