I am currently implementing a nested subscribe operation, although I am aware that it may not be the most efficient method. Here is an example of what I have:
this.route.params.subscribe((params) => {
this.order$
.getMailCommande(this.id)
.subscribe((datas) => {
var Object = localStorage.getItem('dataCommand');
var test = JSON.parse(retrievedObject);
this.over = test.over;
while (this.over == false) {
this.order$
.getMoreInfo(this.id, this.type, this.nbr)
.subscribe((datas2) => {
var array = datas2.MoreInfo;
var Object2 = localStorage.getItem('dataCommand');
var test2 = JSON.parse(Object2);
test2.ListeInfo.push(array);
this.over = true;
});
}
However, the addition of the loop has resulted in an infinite loop. I am exploring the possibility of refactoring this code using switchmap or operators from RxJS, but have not yet been successful.
Does anyone have any suggestions on how to avoid the infinite loop while maintaining the same logic?
Thank you in advance.