<div style="width:100%;height:100%;position:relative;background-color:white" id ="OuterSvg"> </div>
onPageLoaded(){
console.log(document.getElementById("OuterSvg").offsetHeight); //get 0.
}
ngAfterViewInit(){
console.log(document.getElementById("OuterSvg").offsetHeight); //get 0.
}
私はonPageLoaded()とngAfterViewInit()を試していますが、動作しません... DOMの高さがレンダリングされた後、要素の高さ/幅を取得する方法は?angular2のDomの高さを取得するには?
http://stackoverflow.com/a/294273/217408に関連する可能性があります - 最初のコメントを見るか、 'getBoundingClientRect()。height'を試してください –
@GünterZöchbauergetBoundingClientRect()。heightも0を返します。コメントとして、私はsettimeoutメソッドを使うべきですか?角度は、要素のDOMの準備が整った後に高さを得ることができる関数を持っていますか? –