【发布时间】:2019-06-18 02:28:20
【问题描述】:
我有一项服务可以从服务器获取列表。但是在这个列表中我需要调用另一个服务来返回徽标 img,服务返回 ok,但我的列表仍然是空的。我做错了什么?
我尝试在这两个服务中使用 async/await 稍后我尝试使用单独的函数来获取徽标,但我的 html 没有改变。
async getOpportunitiesByPage(_searchQueryAdvanced: any = 'active:true') {
this.listaOportunidades = await this._opportunities
.listaOportunidades(this.pageSize, this.currentPage, _searchQueryAdvanced)
.toPromise()
.then(result => {
this.totalSize = result['totalElements'];
return result['content'].map(async (opportunities: any) => {
opportunities.logoDesktopUrl = await this.getBrand(opportunities['brandsUuid']);
console.log(opportunities.logoDesktopUrl);
return { opportunities };
});
});
this.getTasks(this.totalSize);
}
没有错误,只是我的 html 没有改变。 在我的 控制台.log(机会.logoDesktopUrl); 返回未定义
但最终返回填充。
信息: 角 7 服务器亚马逊 AWS。
【问题讨论】:
-
this.getBrand()是否返回一个 Promise? -
不,一个简单的服务
getBrand(brandsUuid) { this .brandService .getById(brandsUuid) .subscribe( res => { console.log(res.logoDesktopUrl); return res.logoDesktopUrl; }); }
标签: javascript angular