我已经消耗了一个有json响应的http url
[
{
_id: "5a22ff88a06b10436a9da55f",
updatedOn: "2017-12-02T19:31:20.026Z",
createdOn: "2017-12-02T19:31:20.026Z",
createdBy: "Vishal Patel",
status: "o",
penddate: "2017-12-20T00:00:00.000Z",
pstartdate: "2017-12-03T00:00:00.000Z",
name: "vishal patel",
epmid: "e100",
pid: "1000",
__v: 0
}
]
使用以下代码在.service.ts文件中
getProjects(): Observable<MaterialList[]>
{
return this.http.get<MaterialList[]>(this.url)
.pipe(
tap(projectlist => this.log(`FetchedList`)),
catchError(this.handleError('getProjects',[]))
);
}
<{1>}文件中的
使用了这个
abc.component.ts
我已经检查过使用它了
projectlist: MaterialList[] = [];
this.getProjectsList.getProjects().subscribe(projectlist => this.prrojectlist = projectlist['']);
但无法在this.getProjectsList.getProjects().subscribe(projectlist => { this.prrojectlist = projectlist['']});
中获得回复。
我跟随了来自angular.io
的英雄教程请帮助我是Angular2 typescript2的新手。
答案 0 :(得分:0)
您已将空白数组分配给结果数组。
请将此代码从此this.getProjectsList.getProjects().subscribe(projectlist => this.prrojectlist = projectlist['']);
修改为此this.getProjectsList.getProjects().subscribe((data) => this.prrojectlist = data);