Calling an Angular service can be done like this:
this.webService.add(id)
.subscribe(result => {
// perform required actions
}, error => {
// handle errors
});
// Service Definition
add(id: number): Observable < any > {
return this.http.post(this.baseUrl + 'webservice/add/' + id, null);
}
If you need to make multiple calls but ensure that all have completed before displaying a final success or failure message, how can you achieve that?
Would using a recursive method work, or is there a more suitable angular/javascript/callback approach?
For example:
for (let i = 0; i < someLength; i++) {
this.webService.add(id)
.subscribe(result => {
// perform required actions
}, error => {
// handle errors
});
}
// Now display if they all succeeded or if one failed!
The controller appears asynchronous in the following manner:
[HttpPost("document/{id}")]
public async Task<IActionResult> Document(int id) {
// do something
var resultDto = await _webRepo.AddToWebService(info);
return Ok(resultDto);
}