我正在尝试 使用or获取此<div class="bundles-wrap enterprise"
元素的像素高度。getBoundingClientRect().height
this.elementView.nativeElement.offsetHeight
这是我的 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>
这是我的组件类:
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);
}
});
}
我试图得到height1, height2
,但它说Cannot read property 'getBoundingClientRect' of null in Angular
。没有工作。