Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Waiting until method is finished

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading