Skip to content

Instantly share code, notes, and snippets.

@emanuer
Last active May 3, 2020 23:26
Show Gist options
  • Save emanuer/f2a14897bf3084e5e0ce0a04c240a1c6 to your computer and use it in GitHub Desktop.
Save emanuer/f2a14897bf3084e5e0ce0a04c240a1c6 to your computer and use it in GitHub Desktop.
In Angular4: set height of elements after the page was initialized
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