I am trying get data back from a Angular 4 service after making a HttpClient post request, I can see that the data is coming back in the subscribe method, but I cannot pass it to the other variables in the method; Below is my code from the component calling the service:
=========Service Method ==============
autheticateUser(name: string, pass: string) {
const info: any = {};
info.userName = name;
info.password = pass;
return this._http.post<Itoken>(this.url, info)
.shareReplay()
.do((data)=> {this.jwtToken = data;});
}
=============Component calling this service ==========
login() {
this.flag = true;
this.mode= 'indeterminate';
this.authuser.autheticateUser(this.user.userName,this.user.password)
.subscribe((data)=> {this.localtoken = data;});
console.log(this.localtoken); // No value this.localtoken variable
console.loginside the subscription.Currently you are trying to view what's inlocaltokenbefore it arrived - TheUnreal