Reputation: 15
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.
Upvotes: 1
Views: 30
Reputation: 444
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()
});
Upvotes: 1