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;
  });
}

Explanation

These callbacks don't run during SSR, which makes them a safe place for browser-only DOM work.

Further reading

Problem with a question

Angular · Middle · question 60

Test yourself

Take the Angular · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz