Angular 指令根据 window 高度动态调整组件高度
Angular directive to adjust your component Height as per window height Dynamically
Angular 指令根据屏幕动态调整 div/components(Elements) 的高度
import { Directive, ElementRef, Renderer2, AfterViewInit } from '@angular/core';
@Directive({
selector: '[appAutoFullHeight]'
})
export class AutoFullHeightDirective implements AfterViewInit {
constructor(
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() {
}
}
Angular 指令根据屏幕动态调整 div/components(Elements) 的高度
import { Directive, ElementRef, Renderer2, AfterViewInit } from '@angular/core';
@Directive({
selector: '[appAutoFullHeight]'
})
export class AutoFullHeightDirective implements AfterViewInit {
constructor(
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() {
}
}