Last active
          May 3, 2020 23:26 
        
      - 
      
 - 
        
Save emanuer/f2a14897bf3084e5e0ce0a04c240a1c6 to your computer and use it in GitHub Desktop.  
    In Angular4: set height of elements after the page was initialized 
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import {Component, ElementRef, AfterViewInit, QueryList, ViewChild, ViewChildren} from '@angular/core'; | |
| @Component({ | |
| selector: 'app-something', | |
| templateUrl: '<section #fa1><div #fa1View></div><div #fa1View></div></section>', | |
| styleUrls: [''] | |
| }) | |
| export class AppComponent implements AfterViewInit { | |
| @ViewChild('fa1') fa1: ElementRef; | |
| @ViewChildren('fa1View') fa1Views: QueryList<ElementRef>; | |
| ngAfterViewInit() { | |
| this.viewHeight = window.innerHeight - document.getElementById('parrent-Element').offsetTop; // get max height | |
| this.fa1.nativeElement.style.height = this.viewHeight + 'px'; // set height | |
| for (let l = 0; l < this.fa1Views.toArray().length; l++) { | |
| this.fa1Views.toArray()[l].nativeElement.style.height = this.viewHeight + 'px'; | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment