Home > Software engineering >  Waiting until method is finished
Waiting until method is finished

Time:01-04

I have an array public trackedElements: TrackingEvent[]; in which I write data:

this.trackedElementService.trackingEventsGetTrackingEventsbyElementIdFromtimestampTotimestampElementIdGet(this.fromDate.toISOString().slice(0, 10), this.toDate.toISOString().slice(0, 10), this.trackedElement.elementId.toString()).subscribe((data: TrackingEvent[]) => {
   this.trackedElements = data;
});

I call this method the moment the component is initialized, but this.trackedElements doesn't have all the data when the next method is already called in which I want to use the data.

My goal is to figure out how to stop the next method to be called until this.trackedElements is filled completely.

CodePudding user response:

Please try calling the next method after variable has data

this.trackedElementService.trackingEventsGetTrackingEventsbyElementIdFromtimestampTotimestampElementIdGet(this.fromDate.toISOString().slice(0, 10), this.toDate.toISOString().slice(0, 10), this.trackedElement.elementId.toString()).subscribe((data: TrackingEvent[]) => {
   this.trackedElements = data;
// please call next method here like, this.nextMethod()
});
  •  Tags:  
  • Related