在我的角度應用程序,我有他們執行我需要推遲,直到值可用來自後端的方法:這是方法:把我的功能到一個異步函數
redrawGrid(params: any): void {
params.node.childFlower.setRowHeight((this.globalRowCount * 34) + 34) ;
this.gridOptions.api.onRowHeightChanged();
}
我需要這個方法執行AFTER this.globalRowCount(作爲從服務返回的全局值)從後端返回。
變量this.globalRowCount從訂閱即將觀察到的
this.userlistService.childRowLength.subscribe((num: number) => {
this.globalRowCount = num;
console.log(this.globalRowCount + ' globalRowCount after num assigned');
});
我讀,我可以讓這個功能異步和使用的await ...?我將如何做到這一點?
你試過了什麼?你看過承諾嗎? –
需要對實際調用'redrawGrid'的代碼進行更改。一旦'this.globalRowCount'被更新,代碼應該只調用'redrawGrid'。你根本不必改變'redrawGrid'(至少不能根據你提供的信息來判斷)。 –
異步等待需要發生在你得到的globalrowCount函數不在使用它的函數中。 – rjustin