How to Map Response object returned by Http Service to a TypeScript Objects using Observable Map function in Angular2

*爱你&永不变心* 提交于 2019-12-05 02:35:27

Wouldn't this work? I don't see any variable on your code that is a type of IPagedResponse

    pageResponse: IPagedResponse<MileStoneModel>;

    getTypedPagedMilstones(page: number, pageSize: number): Observable<IPagedResponse<MileStoneModel>> {
        return this.http.get(this.url + "/" + "/" + pageSize)
            .map((res: Response) => {
                this.pageResponse.data = <MileStoneModel[]>res.json();
                this.pageResponse.total = res.json().Total;
            })
            .catch(this.handleError);
    }
Yashveer Singh
getPagedMilestones(page: number, pageSize: number): Observable<IPagedResponse<MileStoneModel>> {

    return this.http.get(this.url + "/" + page + "/" + pageSize)
        .map((response: Response) => {
            return {
                data: <MileStoneModel[]>response.json().Data,
                total: response.json().Total
            }
        })
        .catch(this.handleError);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!