Angular directive to adjust your component Height as per window height Dynamically


Angular directive to adjust the height of your div/components(Elements) Dynamically as per screen


    import { Directive, ElementRef, Renderer2, AfterViewInit } from '@angular/core';

  selector: '[appAutoFullHeight]'
export class AutoFullHeightDirective implements AfterViewInit {
    private el: ElementRef,
    private renderer: Renderer2
  ) {
    const windowHeight = window.innerHeight > 600 ? window.innerHeight : 600;
    const calculatedheight = `${windowHeight - 150}px`; // can be simply windowheight but you can do the adjuscement here
    this.renderer.setStyle(this.el.nativeElement, 'height', calculatedheight);


  ngAfterViewInit() {



Answered By – Sourav Raj

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published