Я пытаюсь отказаться. асинхронных c вызовов API и после того, как все они будут возвращены и разрешены в Promise.all.
if(this.selectedDomains.length > 0) {
for(let i=0; i<this.selectedDomains.length; i++){
promises.push(
this.policyService.exportPolicies(this.selectedDomains[i].id, this.config['data'].policies)
);
}
//wait for all exportPolicies calls to finish
Promise.all(promises).then(function () {
console.log("ALL resolved !!");
let successMsg = this.translate.instant("policy.resources.export_policy_success",
[this.config['data'].policies.length, this.selectedDomains.length]);
this.messageHelperService.showSuccess({hide: true, message: successMsg});
}
).catch(function () {
});
}
Здесь this.policyService.exportPolicies - asyn c API вызов, но он никогда не выполняется, и я вижу консольное сообщение ВСЕ разрешено !!
Как мы можем сделать Promise.all разрешенным после всех вызовов asyn c API в promises массив разрешен?
детали вызова API:
export class PolicyService {
constructor ( private baseService : BaseService ) {
}
exportPolicies(domainId, policyIds) : Observable<import("@angular/common/http").HttpEvent<any[]>>{
let url = COMMON.LEGACY_API_PATH + `policy/exportPolicy/${domainId}`;
return this.baseService.postData(url, policyIds);
}
export declare class BaseService {
private http;
constructor(http: HttpClient);
handleError<T>(operation?: string, result?: T): (error: any) => Observable<T>;
log(message: string, response: object): void;
deleteData(url: string, data?: any): Observable<import("@angular/common/http").HttpEvent<any[]>>;
getData(url: string): Observable<any[]>;
postData(url: string, data?: any, params?: any): Observable<import("@angular/common/http").HttpEvent<any[]>>;
putData(url: string, data?: any, params?: any): Observable<import("@angular/common/http").HttpEvent<any[]>>;
patchData(url: string, data?: any, params?: any): Observable<import("@angular/common/http").HttpEvent<any[]>>;
headData(url: string): Observable<any[]>;
static ɵfac: ɵngcc0.ɵɵFactoryDef<BaseService, never>;
}