Angular获取组件大小

时间:2017-12-05 21:57:28

标签: angular angular-router

使用@ angular / router 5.0.5,

何时获得组件高度/宽度是否安全? (不知道如果可能的话,使用@ angular / router)。

ngAfterViewInit不起作用,因为在切换到页面后,有两个ng-component同时呈现 。上一页和新页面:

enter image description here

由于我使用的是flex,它的分割大小是我的组件大小的一半......当然,太快看不到它,但足以得到错误的大小。

我认为角度可以做到允许某种过渡。

<{1}}里面的setTimeout工作正常,但还有什么比这更好的吗?

(我真的很惊讶没有人谈论这种行为,我做错了吗?)

1 个答案:

答案 0 :(得分:0)

到目前为止,我发现的最佳方法是在NgZone.onStable(ngAfterViewInit)中获取大小:

this.zone.onStable.pipe(first()).subscribe(() => {
// get the component size here
}