we need to arrange item in fixed format (by category) that are comming from multiple API's response ex: first to need to display all laptops, second display all PC's and so on..
//fixed order
this.itemList = [{
id: '1',
name: 'Apple',
category: 'LAPTOP'
}, {
id: '2',
name: 'HP',
category: 'LAPTOP'
}, {
id: '3',
name: 'DELL',
category: 'PC'
}, {
id: '4',
name: 'SAMSUNG',
category: 'MOBILE'
}, {
id: '5',
name: 'LENOVO',
category: 'MOBILE'
}];
here we don't want to call parallel api because of response delay, we need to show items according to api response but on ui the format fixed once all api response completed. Here is method for calling api:
loadItems() {
this.itemList = [];
this.itemService.getItems('LAPTOP').then((items) => {
this.itemList = this.itemList.concat(items);
});
this.itemService.getItems('PC').then((items) => {
this.itemList = this.itemList.concat(items);
});
this.itemService.getItems('TABLET').then((items) => {
this.itemList = this.itemList.concat(items);
});
this.itemService.getItems('MOBILE').then((items) => {
this.itemList = this.itemList.concat(items);
});
}
So, if mobile api's response comes first, ui will display mobile items, after that if laptop api's response comes, it will show laptop first with maintain above format. thanks
orderByin your repeat but that will have a particular order and not like whichever comes first