【发布时间】:2017-10-12 19:11:24
【问题描述】:
在我的 Angular 应用程序中,我有一个方法,我需要推迟它的执行,直到后端的值可用:这是方法:
redrawGrid(params: any): void {
params.node.childFlower.setRowHeight( (this.globalRowCount * 34 ) + 34) ;
this.gridOptions.api.onRowHeightChanged();
}
我需要这个方法在 this.globalRowCount(作为从服务返回的全局值)从后端返回之后执行。
变量 this.globalRowCount 来自对 observable 的订阅
this.userlistService.childRowLength.subscribe( (num: number) => {
this.globalRowCount = num;
console.log(this.globalRowCount + ' globalRowCount after num assigned');
});
我读到我可以使这个函数异步并使用等待......?我该怎么做?
【问题讨论】:
-
你试过什么?你看过承诺吗?
-
需要对实际调用
redrawGrid的代码进行更改。代码只应在this.globalRowCount更新后调用redrawGrid。实际上,您根本不必更改redrawGrid(至少据我所知,鉴于您提供的信息)。 -
异步等待需要发生在获得 globalrowCount 的函数中,而不是在使用它的函数中。
标签: javascript angular typescript asynchronous