Enviroment AngularJS 4
I try to run a HTTP Request in a function, but i can not send the result back.
Beloow have post my code with some comments.
I just need the true
or false
value but i receive nothing.
I struggling with this issue for a while and don't find a explaination and solution. Does someone can give me a hint?
public runLoginProcess(username:String, password:String):boolean{
let body= { "username":username,"password":password };
let head = new Headers();
head.append("Content-Type", "application/json");
head.append("Accept", "application/json");
// RUN THE HTTP CALL AN IF IT WORKS, SEND TRUE AND ERROR IN CASE OF AN ERROR BACK
this.http.post("<PATH TO MY SERVICE>", body)
.subscribe(response => {
let token = response.json() && response.json().token;
if (token) {
localStorage.setItem('currentUser', JSON.stringify({"username": username, "token": token}))
return true;
}
},
error2 => {
return false;
}
);
}