just imagine: 1. in component.html, you have
<div id = "myDiv">
<p>{{text}}</p>
<div>
<button (click)="changeText()">changeText</button>
in component.css / we do not set the height of div explicitly. The height of div depends on the height of p element. In other words, the number of words inside p decides the height of div
in component.ts there is a function, which we can call it anytime and set the {{text}} property. So the div and p get rendered at runtime and dynamically. Like:
export class someComponent implements OnInit {
constructor(private el: ElementRef) { }
ngOnInit() {
}
changeText() {
this.text = 'blablablabla.....';
let divEl = this.el.nativeElement.querySelector('#myDiv');
divEl.clientHeight/ or offsetHeight or/ getComputedStyle (can not get the correct value here!)
}
}
Q: how can we get the actual height of the div after I change the text. (I can get the element by ElementRef) I have tried .offsetHeight, .clientHeight, .getComputedStyle.height....// It seems like all of them return the original value, not the actual value at runtime.