我有以下代码从我的服务返回分页结果。我刚刚切换到角度5,现在代码不再工作了
return this._http.get(
this.userManagerResourceApiUrl + "GetAllUsers/" + tierID + "/" + countryID + "/" + officeID + "/" + filter
).map((res: Response) => {
paginatedResult.result = res.json();
if (res.headers.get("Pagination") != null) {
var paginationHeader: Pagination = this.itemsService.getSerialized<Pagination>(JSON.parse(res.headers.get("Pagination")));
paginatedResult.pagination = paginationHeader;
}
this.totalItems = paginatedResult.pagination.TotalItems;
return paginatedResult;
}).catch(this.handleError);
我收到以下错误消息
Type 'Promise<any>' is not assignable to type 'IUser[]'
答案 0 :(得分:1)
在角度5中,您不再需要映射到json并删除任何不再需要的map(res => res.json())
次呼叫。
将项目升级为angular 5时需要注意的事项。 https://onlyforcoder.blogspot.in/2017/11/angular-5-upgrade-your-project-To-Angular5.html