<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方法?但angulars是否有任何功能可以在元素dom准备好后获得高度? –