【发布时间】:2017-10-08 12:04:03
【问题描述】:
我有一组部分,我正在尝试获取并显示每个部分下的所有项目。这似乎是一个非常简单的方法。这是我的代码:
//my ngOnInit call this function
this.sectionService.GetItemList(this.selectedSectionList, this.culture)
.subscribe(
(itemList: ItemBySection[]) => {
this.itemBySection = itemList;
this.loaded = true;
},
(error: any) => this.errorMessage = error, () =>
console.log("loaded")
);
//this is my function in my service
public GetItemList(SectionItems: Sections[], strCulture): Observable<ItemBySection[]> {
let resultObservable
for (var SectionItem in SectionItems) {
let url = environment.portalWebServiceURL + "api/section/" + SectionItems[SectionItem].sectionItemID.toString() + "/" + strCulture;
resultObservable = this.http.get(url)
.catch(this.handleError)
.mergeMap(res => <ItemBySection[]>res.json());
}
return resultObservable;
}
也许我上面的解释不太清楚 所以我想做的是在一个循环中多次调用我的网络服务并将结果连接到一个列表中。也许这会有所帮助。
for all my sectionIDs {
call url web service with sectionID
receive results from server
add the results in my item array
}
finally display all items.
希望对你有所帮助。
【问题讨论】:
标签: angular loops rxjs observable