i have this code that calls an api for every object of a list "titles" and add the object to another list "groupDocs". but since the response of the api is not immediate the order of objects changs in the list "groupDocs". what should i do to keep the same order?
i can't find a solution to this problem and i am new to angular.
public getDetails(titles: ErrorTitleData[]): void {
for (const title of titles) {
const showButtons: boolean = false;
const details: controlErrordetailsData[] = [];
const criteria: SearchCriteriaControlData = {
aggFields: ['Famille', 'Sous-Famille', 'Date', 'Controle', 'erreur'],
page: 0,
step: 20,
selectedValues: {},
queryString: ''
};
criteria.selectedValues['Sous-Famille'] = [title.sf ? title.sf : ''];
criteria.selectedValues['Date'] = [title.dateVerif ? title.dateVerif : ''];
criteria.selectedValues['Controle'] = [title.typeVerif ? title.typeVerif : ''];
this.controlErrorService.getErrorControl(criteria).subscribe(
(data) => {
data.hits.forEach(element => {
const detail: controlErrordetailsData = new controlErrordetailsData(element);
details.push(detail);
});
this.groupDocs.push(new GroupDoc(title, details, criteria, data.total));
},
(error) => {
this.toastService.update(ToastService.TYPE_ERROR,
'Une erreur est survenue lors du chargement de la liste des contrôle d\'erreurs');
}
);
}
}