0

How to calculate each and every page height from top to bottom in angular ? This syntax work in JavaScript but give error in angular

console.log( (document.height !== undefined) ? document.height : document.body.offsetHeight+'px');

What I want is to have each page height but when items are added dynamically , it should give me the new height of page.

1
  • Can you show the error gave in angular ? Commented Jan 5, 2022 at 10:11

2 Answers 2

0

Try this instead:

console.log(window.innerHeight);
Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0
import { Component, ElementRef, Renderer2, OnInit } from '@angular/core';

@Component({
  selector: 'app-component',
  template: '<p *ngFor='let item of arr'>item {{item?.name}}</p>',
})
export class YourComponent implements OnInit {
arr=[];
  constructor(private el: ElementRef, private renderer: Renderer2) {}

  ngOnInit() {
    this.calculatePageHeight();
    setTimeout(() => {
      this.addElementToDOM();//like your API call
      this.calculatePageHeight();
    }, 4000); // Adjust the delay based on your use case
  }

  addElementToDOM() {
    this.arr=[
.......
];
  }

  calculatePageHeight() {
    const documentHeight = Math.max(
      document.documentElement.clientHeight,
      window.innerHeight || 0
    );

    console.log('Updated Document Height: ' + documentHeight + 'px');
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.