I have a question. In my program i need to update few records on server so i need to do this throught the loop. And after all i need to get new infrmation from server. The problem is how can i wait till all http.put response with 201?
Now some code : I have an update function inside service:
public updateDataonServer(rodz: string, id: number, bodyContent: any) {
let body = JSON.stringify(bodyContent);
let headers = new Headers({ 'Content-Type': 'application/json' });
this.currentUser.setHttpHeader(headers);
let options = new RequestOptions({ headers: headers });
return this._http.put(serverAdress + '/rin/' + rodz + '/' + id,
body,
options).map(res => res.status).catch(this.handleError);
}
and i use it in this function:
changeShow(showId: number, oldShow: MpGruppedGroup[]) {
for (var show of oldShow) {
var paramsDict = {
'DAILY_PLAN_GROUP_ID': show.dailyPlanGroupId,
'DAILY_AIRINGS': show.dailyAirings,
'SHOW_ID': showId
};
this.manager.updateDataonServer('MP_GROUPED', show.dailyPlanGroupId, paramsDict).subscribe((data: any) => {
console.log('status ', data);
});
}
// that should be done after all updates return 201 status
this.getShowDayGroups(showId);
}