angular2 services - Implement ngDoCheck when a list object change on angular 2 -
in case have function , inside calling nested api in loops. want call function when calls completed inside loops. calling function outside loop called before completion of loop.did use ngdocheck checking continuously.
this code
this.cmsservice.listservicebyproductandparentservice(productid,parentserviceid).subscribe(servicelist=>{ for(let i=0;i<servicelist.length;i++){ if(servicelist[i].has_children){ this.cmsservice.listservicebyproductandparentservice(productid,servicelist[i].id).subscribe(services=>{ for(let j=0;j<services.length;j++){ this.cmsservice.listpricebyserviceid(productid,services[j].id).subscribe(res=>{ servicelist.push(res); }) } }) console.log("removed service list is",servicelist[i]); servicelist.splice(i,1); } else{ this.cmsservice.listpricebyserviceid(productid,servicelist[i].id).subscribe(pricelist=> { servicelist[i]=pricelist; }) } } console.log("servicelist is",servicelist); this.services=servicelist; this.doreset(); this.doinitadd(); })
Comments
Post a Comment