Questions tagged asynchronous

Explore the latest questions and answers asked by our top developers.

Angular call to REST API not waiting for the data to arrived

I have the following code: export class Whatever implements OnInitn{ prices; ngOnInit(){ this.CoinPricesService.getPrices().subscribe( pricesFromResponse => { this.prices = pricesFromResponse; console.log(‘this is what I get from the api: ‘, this.prices); } ); console.log(‘this is my prices class object’, this.prices); } } the output is this: this is my prices class object undefined api: this is what […]

use promise in array items inside a Map object

I need to iterate over a Map object – to make it realistic – lets say it is a collection of Polygons (Polygons is represented by a collection of coordinates – lat and long). Every item in the Map has a collection of items (coordinates). With every item (coordinate) in the Map (polygon), I need […]

By Guy E
Published
Categorized as angular, asynchronous, promise, rxjs, typescript Tagged , , , ,

How to Promise data from Subject?

This code only Promises the Subject itself, not the data: getOption() { return this.subject; } getData() { this.getOpt().then(data => this.subject = data); } getOpt(): Promise<Subject<any>> { return this.globalFooService.getObservable().toPromise(); } I tried implementing pipe, tap and first but dunno what to import from rxjs for them. Also am trying to avoid subscribe because of previous question. […]

By ForgiveMyParlance
Published
Categorized as angular, asynchronous, promise, rxjs, subject Tagged , , , ,

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 […]

By melvin
Published
Categorized as angular, arrays, asynchronous, typescript Tagged , , ,

Rendering angular component conditionally based on its input variable doesn’t infer the existence of the input variable

I have an angular component with an array of Input variables that is asynchronously initialized in the parent. @Component({ … }) export class ChildComponent { @Input inputVariable: string; } @Component({ … }) export class ParentComponent implements OnInit { inputVariables: string[] = []; constructor( private http: HttpClient ) { } ngOnInit(): void { this.http.get<string[]>(‘someUrl’) .subscribe(res => […]

how to subscribe an observable asynchronously from an array – angular

I have an array contains IDs and I want to subscribe to an observable for each ID in the array in an orderly manner (make a request for id 1 then 2 …). I’ve tried foreach loop but the responses were unordered. and tried to create a for loop and increase the index from the […]

Angular Service with multipe select filter with observables

I have a service class returning Observable array of items and takes filter object like this: export interface Filter { filter1: string; filter2: string; } export class Serivce { getItems(f: Filter): Observable<myResult[]> { // make http call } } Now I want to display the getItems result in my component using async pipe like this: […]

By Dennis
Published
Categorized as angular, asynchronous, observable, pipe Tagged , , ,

Waiting for multiple RxJS call before executing the next code block

I hava a list of streets and iterate over them. Inside the for loop i gonna call an endpoint for each of these streets. The endpoint gives me informations about the requested street. I wanna store each response into an Object Array and after ALL requests finished, i wanna execute the next code block. Here […]

Set a function to await response when calling through another function

Using JavaScript and AngularJS, I have a controller function looking to set a bool based on the return of a service call, which awaits the return of an API call. How do I write the controller function to wait for the API response? Controller… var myVariable = false; function firstCheck() { // function checks other […]

By TMR
Published
Categorized as angularjs, asynchronous, javascript Tagged , ,

Angular Universal SSR | I want to use a async function, but I can’t

I am developing a simple sign in system and I want have the input value every time after 100ms, to do that I created this Async function: waitforme(ms: number) { return new Promise( resolve => { setTimeout(resolve, ms); }); } async printy(boll: boolean) { while(boll) { await this.waitforme(100); // loop will be halted here until […]

1 2 3 23

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq