Angular · Middle · Question 60 of 75
How do you measure a DOM element's size after the component renders?
constructor() {
afterNextRender(() => {
this.height = this.el.nativeElement.offsetHeight;
});
}- ✓Correct answer: Use
afterNextRender(orafterEveryRender), which runs after Angular updates the DOM in the browser - 2Read it in the constructor
- 3Read it in
ngOnChanges
Explanation
These callbacks don't run during SSR, which makes them a safe place for browser-only DOM work.