I'm having an issue with calling a service in my component, causing the data to always go null. Here is an example of the code:
The service method :
getOneUser() {
return this._http.get(globals.serverIp + '/user/getOneUser/' + this._ls.getCurrentUserName(), { headers: this.headers})
.map((response: Response) => <UserParser> response.json());
}
The method in the component :
updateParametre(message: string){
let currentUser = new User();
this._us.getOneUser().subscribe(
data =>currentUser = data.data,
error => console.log('error from updateParam ParamtereComponenet ' + error),
() => console.log(currentUser)
);
let anotherinstance : User = currentuser ;
console.log(currentUser);
}
Attempting to console log the currentUser inside the subscribe method:
{id: 9,
initials: "YCI",
nom: "CHABLI",
prenom: "Yassin",
password: "$2a$10$iWVnXs/2TwOk7CBr5RuQ.e/1c/BTlxsvkjHyYrtOgKUiRMll2EupO"}
However, the object `anotherintance` becomes null, and trying to console log the `currentUser` outside of the subscribe also results in null.
What could be causing this issue? Please help.