一旦区域稳定,我将尝试使用ngZone来更新我的分页状态,以便我尝试分页的组件将被完全呈现,并且我将从呈现器获得正确的scrollWidth。
在Angular Material 2代码中使用它的方式是这样的:
// 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的正确方法是什么?
发布于 2018-01-23 22:47:39
// 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();https://stackoverflow.com/questions/47022311
复制相似问题