Questions tagged asynchronous

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

Assign value to variable when ajax call finish [duplicate]

I’m developing an Angular WebApp and I would like to assign the value coming from an AJAX call to a variable. Actually, I tried many different solutions without good results. let a = testFunction(); testFunction(){ let b; $.ajax({…}).done(function(e) { b = e + 1 }); return b } console.log("The value of ‘a’ plus the value […]

By teo
Categorized as ajax, angular, async-await, asynchronous, javascript Tagged , , , ,

Angular asynchronous request not loaded in time

I am experiencing some issues with a tricky asynchronous request I am trying to perform in Angular. I am displaying a user interface with specific information condensed in a table. The table contains headers that are loaded from a backend using a http.get method provided by the HttpClient module. I call this method in the […]

By Guusda
Categorized as angular, asynchronous, frontend Tagged , ,

Angular Async Functions

In my angular project, I have some booleans that trigger my NgIfs. I want to be able to reset all booleans to false and then set the one relevant boolean to true. here is an example of my code: resetBooleans(){ this.mainBoolean = false; this.secondBoolean = false; this.thirdBoolean = false; } doSecondThing(){ this.resetBooleans(); this.secondBoolean = true; […]

By AndreTheTallGuy
Categorized as angular, asynchronous, typescript Tagged , ,

How to create proper asynchronous validators in Angular?

I’m trying to create a simple asynchronous validators in Angular to make sure that a username is not duplicated: THE VALIDATOR CLASS: import { AbstractControl, ValidationErrors } from "@angular/forms"; export class UsernameValidators { static shouldBeUnique(control: AbstractControl): Promise<ValidationErrors | null> { return new Promise((resolve, reject) => { setTimeout(() => { if (control.value === ‘Robert’) { resolve({ […]

By HeyLameRobin
Categorized as angular, asynchronous, validation Tagged , ,

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

1 24

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