【发布时间】:2018-12-06 12:14:56
【问题描述】:
根据我的要求,我需要使用 Angular 6 Httpclient 发送异步请求。
谁能解释一下如何发送异步请求?
组件中的循环调用:
REST API 服务中的函数:
现在,所有请求都在进行中。但我希望在完成第一个请求后,第二个请求应该去等等。
请告诉我这在 Angular 6 中是否可行?
请试着给我一些好的例子。
this.pressArray.forEach(function(field_value, field_index){
restAPI.CallAddPageBlock(formData, '', id).subscribe(response2 => {
content_blocks.push(response2.id);
});
});
CallAddPageBlock(formData, tickets='', id): Observable<any> {
var full_url = this.baseUrlContent + 'Hub_PageBlock_C/assets/';
if(id!=0){
full_url = full_url+id
}
return this.http.post(full_url, formData, this.httpOptionsJson).pipe();
}
【问题讨论】:
-
是否有一个班级被分配了这项工作,或者这纯粹是巧合?我在一小时或三小时前刚刚回答了一个非常相似的问题:Execute http request sequentially in Angular 6