У меня есть демо Здесь
У меня есть div в компоненте, который отображается с * ngIf
Мне нужно знать высоту этого элемента.
Кажется, я не могу сделать это до того, как оно отобразится или в функции, которая показывает элемент.
Есть ли событие, которое я могу использовать, чтобы получить высоту
import { Component, Input, ElementRef, OnInit, ViewChild, AfterViewInit } from '@angular/core';
@Component({
selector: 'child-comp',
templateUrl: './child.component.html'
})
export class ChildComponent implements OnInit, AfterViewInit {
@Input() parent: ElementRef;
private block: ElementRef;
@ViewChild('block') set content(content: ElementRef) {
this.block = content;
}
show: boolean = false
blockHeight: number
constructor(){ }
// ngOnInit(){
// this.blockHeight = this.block.nativeElement.clientHeight;
// }
ngAfterViewInit(){
this.blockHeight = this.block.nativeElement.clientHeight;
console.log('AfterViewInit '+this.blockHeight);
}
showBlock(){
this.show = !this.show
this.blockHeight = this.block.nativeElement.clientHeight;
console.log('showBlock '+this.blockHeight);
}
}