Quantcast
Channel: User Just code - Stack Overflow
Viewing all articles
Browse latest Browse all 41

How to make a synchronous call in angular 5?

$
0
0

So, I was trying to get the solution of this problem. But, somehow I am unable to do so, May be because of the lack of knowledge in angular 5.This is my service:

GetCurrentUserData(): Observable<ResponseData> {    return this.http.get<ResponseData>(ApplicationURLS.GetCurrentUserInformation)        .map(response => {            return response;        });    //.catch(error => this.handleError(error));}

This is my component:

public GetCurrentUserInformation(): any {        return this.loginService.GetCurrentUserData().subscribe(data => { return data; });    }

Here I am trying to access the data:

ngAfterViewInit() {        debugger;                        this.responseData = this.GetCurrentUserInformation();        if (this.responseData.code != responseCodes.success) {            this.googleInit();        }    }

When I check the this.responseData it is always returning this instead I want data:enter image description here

I just want to make a sync call so I can get the data immediately.

I also tried to use the do() in service but its returning do() is not a function.


Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>