首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ngZone onStable检查组件是否呈现

使用ngZone onStable检查组件是否呈现
EN

Stack Overflow用户
提问于 2017-10-31 02:50:10
回答 1查看 4.7K关注 0票数 4

一旦区域稳定,我将尝试使用ngZone来更新我的分页状态,以便我尝试分页的组件将被完全呈现,并且我将从呈现器获得正确的scrollWidth。

Angular Material 2代码中使用它的方式是这样的:

代码语言:javascript
复制
// Update the position once the zone is stable so that the overlay will be fully rendered
// before attempting to position it, as the position may depend on the size of the rendered
// content.
this._ngZone.onStable.asObservable().pipe(first()).subscribe(() => {
  this.updatePosition();
});

我在我的组件中做了同样的事情,运行我自己的方法,而不是'this.updatePosition()‘。但这并不能帮助我获得最新的渲染状态,它仍然运行得太早。

这里我漏掉了什么?在onStable中使用ngZone的正确方法是什么?

EN

回答 1

Stack Overflow用户

发布于 2018-01-23 22:47:39

代码语言:javascript
复制
// Update the position once the zone is stable so that the overlay will be fully rendered
// before attempting to position it, as the position may depend on the size of the rendered
// content.

let that = this;

that.updatePosition();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47022311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档