I am trying to get pixel height of this <div class="bundles-wrap enterprise"
element using getBoundingClientRect().height
or this.elementView.nativeElement.offsetHeight
.
This is my HTML:
<div class="row d-flex align-items-end" *ngFor="let value of valueList">
<!-- start-->
<div class="bundles-wrap enterprise" id="card-id" #card>
<div class="hdr">
<h2>{{value.Name}}</h2>
<span>What you’ll get</span>
</div>
</div>
</div>
This is my component class:
valueList: Model[];
@ViewChild('card', {read: ElementRef, static:false}) elementView: ElementRef;
ngAfterViewInit(): void{
this.loaderService.showLoader("shell-content-loader", "Processing…");
this.getValueList();
}
getValueList(){
this.service.getvalueDetails().subscribe(res => {
this.valueList = res;
if (this.valueList.length != 0) {
this.loaderService.hideLoader("shell-content-loader");
const height1 = document.getElementById('card-id').getBoundingClientRect().height;
const height2 = this.elementView.nativeElement.offsetHeight;
console.log(height1);
}
});
}
And I am trying to get height1, height2
but it says Cannot read property 'getBoundingClientRect' of null in Angular
. None works.