I am trying to convert the Http post response to the Type object
JSON Response from the server
{
"authenticated": false,
"admin": false
}
Angular class to be type casted
export class UserRole {
authenticated: boolean;
admin: boolean;
}
HTTP Post Call
login() {
this.user.password = btoa(this.user.password);
this.http.post(this.url, this.user).subscribe(res => {
console.log(res);
});
if (this.userRole.admin) {
console.log('Going in admin');
this.authService.setLoggedIn(this.user.userId,true);
} else {
console.log('Going in else admin');
this.authService.setLoggedIn(this.user.userId,false);
}
this.router.navigateByUrl('/nav');
}
I am having issues on converting the result on subscribe to UserRole object, should i need to use a JSON.parse or any other method.