Template
<div class="row" *ngFor="let otc of this.jsonData;index as j">
<div>
<table class="table table-striped table-fixed">
<tr *ngFor="let opc of this.winServiceInfo(j);index as i">
Typescript
ngOnInit(): void {
this.geWinService();
}
winServiceInfo(j: number) {
this.winServiceURL = JSON.parse(this.WinService[j].windowsServicesInfo)["Stactuscheck"];
this.dataArrs = [];
this.service.getWinServicesInfo(this.winServiceURL)
.pipe(
catchError(this.handleError)
)
.subscribe(
(data: any) => {
this.setSubscribeData(data);
console.log(this.dataArrs);
return this.dataArrs;
});
console.log(this.dataArrs);
return this.dataArrs;
}
setSubscribeData(data): any {
this.WinService = data.windowsServicesInfo;
this.dataArrs = this.getKeyValJsonObj();
return this.dataArrs;
}
getKeyValJsonObj() {
this.dataArr = [];
for (let key of this.sliceIntoChunks()) {
for (let i in key) {
this.dataArr.push({ 'key': i, 'value': key[i] });
}
}
return this.dataArr;
}
On method winServiceInfo first console.log(this.dataArrs) retuens Arrar(3) but the second console.log(this.dataArrs) returns Arrar(0). I understand that subscribe is an asynchronous operation and for that reason.
So how to handle the situation to return the Array(3) from second console.log(this.dataArrs)