I keep trying to use tutorials but can't seem to figure out how to use Promises or async await.
I have an http GET request and I want to wait for the result from the API before returning. The coming back as null because the function returns before the GET occurs.
HTTP GET
get_UserAccess(practiceId: number, userId: number): UserAccess {
var d: UserAccess;
this.httpclient.get(this.URL).subscribe.(data => {
d = data as UserAccess;
});
return d; //Keeps returning as null
Calling Component
var userAccess = this.dataService.get_UserAccess(this.practice.practiceId, this.users[i].userId);
this.loadAccess(userAccess);
I've tried adding the await and async tags to the get request, but I'm not sure how to work with the promise that it returns to the calling component..