使用Angular 5获取元素的全宽

问题描述 投票:0回答:1

如何获得角度为5的元素的全宽,而不仅仅计算?现在我只得到客户端的宽度而不是元素的整个宽度。

这段代码出了什么问题?

 @ViewChild('box') box: ElementRef;
 ...
 this.boxWidth = this.box.nativeElement.clientWidth;

HTML

 <ion-row nowrap class="time-bar" [ngStyle]="{'left': leftscroll}" #box>
   <p *ngFor="let i of day">{{i}}</p>
 </ion-row>
angular ionic-framework
1个回答
0
投票

使用offsetWidth。它还包括边框宽度

@ViewChild('box') box: ElementRef;
 this.boxWidth = this.box.nativeElement.offsetWidth;
© www.soinside.com 2019 - 2024. All rights reserved.