I am trying to validate a user token by the means of a back-end API. I am brand new to Angular2 in general. My question is, if I want isValidToken to return a boolean value of whether or not the token provided was valid, how can I wait for the HTTP call to complete prior to return in result from isValidToken()?
isValidToken(token: string): boolean {
var isValidToken: boolean = false;
this.getIsValidToken(token).subscribe(
data => {
isValidToken = data.isValidToken;
return isValidToken;
},
error => {
return false;
}
);
}
getIsValidToken(token: string) {
return this.http.get(this.validateTokenUrl + '?tokenString=' + token)
.map(res => res.json());
}