calculating the dynamic height of a document from top to bottom using Angular

Is there a way to dynamically calculate the height of each page from top to bottom in Angular? The syntax that works in JavaScript seems to give an error in Angular.

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

I need to be able to accurately determine the height of the page, even when items are added dynamically. How can this be achieved?

Answer №1

Here's an alternative suggestion:

alert(window.innerHeight);

Answer №2

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 CustomComponent implements OnInit {
arr=[];
  constructor(private el: ElementRef, private renderer: Renderer2) {}

  ngOnInit() {
    this.adjustPageHeight();
    setTimeout(() => {
      this.addCustomElement();//simulate API call
      this.adjustPageHeight();
    }, 4000);
  }

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

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

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to implement the post method in ng2-smart-table whenever a new row is inserted?

Incorporating the ng2 smart table library into my angular 2 project has been helpful. I am now faced with a requirement to trigger an API request using the http.post() method whenever a new row is added to the table. Is there a way for me to retrieve the ...

What is the syntax for typing a mongoose populated field in Typescript?

I am faced with a field that can either be an ID or have a value, and I am attempting to type this field using TypeScript import { InferSchemaType, Schema, Types, model } from 'mongoose'; const personSchema = new Schema({ _id: Schema.Types.Obj ...

Preventing specific directories from being imported in a Typescript project

I am intrigued by the idea of restricting files within a specific scope from importing files from another scope. Let's consider this example: Imagine we have the following project structure: project/ ├── node_modules/ ├── test/ ├── ...

The key provided does not correspond to a constructor object

I have a unique method that implements an interface. This is My Command. import iCommand from './i-command'; export default class Voice implements iCommand { args: String[]; message: any; client: any; config: any; constructor(a ...

Issue arose following the update from Angular 5 to 6, impacting the VSTS build process

Upon upgrading from Angular 5 to 6, I successfully got it running locally. It builds and compiles with --prod. Integration into an .NET MVC application went smoothly. However, when the build on VSTS is triggered, a series of errors surface: node_modules&b ...

Assigning different data types with matching keys - "Cannot assign type '...' to type 'never'."

I have a question regarding my application, where I am utilizing values that can either be static or functions returning those values. For TypeScript, I have defined the static values along with their types in the following manner: type Static = { key1: ...

Filtering observables to handle routing in Angular Material Autocomplete is a must-have skill to master

I am currently working with Angular Material version "^6.4.7" and Angular version "^6.1.9". I have set up routing to navigate through a menu filled with observables, using the id of these observables for navigation. Now, I need to implement an autocomplete ...

What is the best way to retrieve the 5 most recent posts for each genre using Laravel's API

In the process of developing an application (which is my academic project), I am utilizing Laravel 5.4 as my API combined with Angular 5. The focus of my project revolves around a music blog, necessitating specific features like categories and subcategorie ...

Error: Failed to load chunk 552 due to chunk loading issue

Currently in the process of migrating Angular 12 to version 13. The migration itself was successful, however, upon running the project in the browser post a successful build, the application fails to display. On checking the console, I encountered the foll ...

Tips for connecting to multiple items in an md-select element from within a directive

Looking to develop a straightforward directive that displays either a textbox or dropdown based on whether an array is provided for the model property on the scope. Any value other than explicitly setting false in the directive markup such as multiple="fa ...

"Utilizing Postgresql with TypeORM for filtering many-to-many relationships

I have two entities that are connected with a ManyToMany relationship: // Branch entity @ManyToMany( (type) => User, (e) => e.branches ) users: User[]; // User entity @ManyToMany( (type) => Branch, (e) ...

A comprehensive guide on creating and searching for tables in Angular

Seeking guidance on creating a table in Angular to display data fetched from an API. Currently developing a library management project with a reservation feature for books. Working on the search page where users can search and view book information in a ta ...

Why won't T.chain chain properly in Effect-ts?

I have a simple program that I've been working on: import * as T from "@effect-ts/core/Effect"; import { pipe } from "@effect-ts/core/Function"; import { tag } from "@effect-ts/core/Has"; interface ConsoleModule { log: ...

Implementing setDoc with Firebase-Admin using Typescript in Firestore

I'm having issues with my code in config/firebase.ts: import { initializeApp, cert } from 'firebase-admin/app'; import { getFirestore } from 'firebase-admin/firestore' const firebaseAdminApp = initializeApp({ credential: cert( ...

Oops! Looks like there's an issue with the type error: value.forEach is

I am working on creating an update form in Angular 6 using FormArray. Below is the code snippet I have in editfrom.TS : // Initialising FormArray valueIngrident = new FormArray([]); constructor(private brandService: BrandService, private PValueInfoSe ...

Advantages of using ConfigService instead of dotenv

What are the benefits and drawbacks of utilizing @NestJS/Config compared to using dotenv for retrieving environment variables? Although I can create a class to manage all envvars in both scenarios, is it necessary? I am aware that @NestJS/Config relies on ...

Creating rectangular shapes on the canvas with the help of react hooks

I have a React+Typescript web application and I am currently working on implementing the functionality to draw rectangles on a canvas. My goal is to utilize React hooks instead of classes in order to achieve this. The desired outcome is to enable the user ...

Angular 4 Bootstrap 4 Collapsible Navigation Bar

Struggling for a while now trying to achieve the exact functionality I desire. Within my Angular Universal App, there is a vertical navigation bar at the top that I want to make responsive for mobile devices. I am utilizing Bootstrap 4 Alpha 6 and ngx-boot ...

Guide on transforming an Angular 6 project into a Progressive Web Application (PWA)

Currently, my Angular 6 project is up and running smoothly. However, I am looking to integrate PWA into my existing application. When I execute the following command: ng add @angular/pwa The output displays: + @angular/<a href="/cdn-cgi/l/email-protec ...

Highlighting DOM elements that have recently been modified in Angular

Is there a simple way to change the style of an element when a bound property value changes, without storing a dedicated property in the component? The elements I want to highlight are input form elements: <tr field label="Lieu dépôt"> ...