使用Angular 5获取元素的完整宽度

时间:2018-08-29 15:16:00

标签: angular ionic-framework

如何获取角度为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>

1 个答案:

答案 0 :(得分:0)

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

from PyQt5 import QtWidgets, QtCore
class Test(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(Test, self).__init__(parent)
        self.layout = QtWidgets.QVBoxLayout()
        self.listWidget = QtWidgets.QListWidget()
        self.listWidget.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection
        )
        self.listWidget.setGeometry(QtCore.QRect(10, 10, 211, 291))
        for i in range(10):
            item = QtWidgets.QListWidgetItem("Item %i" % i)
            self.listWidget.addItem(item)
        self.listWidget.itemClicked.connect(self.printItemText)
        self.layout.addWidget(self.listWidget)
        self.setLayout(self.layout)

    def printItemText(self):
        items = self.listWidget.selectedItems()
        x = []
        for i in range(len(items)):
            x.append(str(self.listWidget.selectedItems()[i].text()))

        print (x)

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    form = Test()
    form.show()
    app.exec_()