在我的打字稿類中,我有兩個私有變數。一個變數將存盤我從 API 回傳的字串。另一個是我將向用戶顯示的訊息。一旦 API 完成,將使用回傳并構建完整的訊息。在我設定的回應中this.templatIds,它將使用正確的 id 構建訊息。但是在我的彈出訊息中,它缺少字串中的部分。
export class AgentsGridComponent implements AfterViewInit {
private templatIds = "";
private inuseItemMessage = `This Agent is being used by Templates ${this.templatIds} and can't be archived`
this.agentsService.inuseTemplateAgentList(data.item.Id)
.then((response) => {
console.log(response.Value);
this.templatIds = response.Value;
this.notificationManager.error(inuseItemMessage);
});
uj5u.com熱心網友回復:
在templatIds不填充在該時間inuseItemMessage被分配到-他們都獲得分配在同一時間,在建構式的開始。將訊息改為函式,這樣它就可以templatIds根據需要從現在填充的模板字串中構建模板字串。
private getInUseMessage = () => `This Agent is being used by Templates ${this.templatIds} and can't be archived`
this.notificationManager.error(this.getInUseMessage());
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/369884.html
標籤:javascript 打字稿
