2017-04-18 33 views
0

在下面的代碼片段中,我似乎無法訪問.circle的當前margin-left css屬性。我創建了一個PLUNKr這展示了這一點。不能訪問元素margin-left

我想訪問此屬性,因爲我需要在移動設備上調整屬性綁定計算,它需要left-margin

這是什麼,我有一個細分:

<div class="circle" [ngStyle]="{'width': calcCircleWidth()}"></div> 

.circle { 
    margin: 40px 20px; 
} 

private calcCircleWidth(): string { 
    var html: HTMLElement = (<HTMLElement>document.querySelector('.circle:first-child')) 
    ... 
} 

這是結果基於您的代碼,當我登錄的var html: HTMLElement

html \\ <div class="circle" _ngcontent-iai-1="" style="width: 50%;"> 
html.style \\ CSS2Properties { width: "50%" } 
html.style.marginLeft \\ (nothing) 
+0

我的朋友發生了一些瘋狂的事情 - 現在修理它。 – Zze

+0

Plunkr已被修復。 – Zze

+0

Plunker大約是2.0.0-beta.0。這已經超過一年了。只需使用Plunker中的「新建」按鈕即可獲取最新Angular版本的Plunker模板。 –

回答