can someone help me with getting number from http response in Angular 5 ? I don't now how to do it, I was searching at internet but Angular grow very fast so it doesn't help me. Thanks for any help !
My code:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { User } from '../entities/User';
@Injectable()
export class UserService {
private usersurl: 'http://localhost:8080/api/users';
user: User;
id: number;
constructor(private http: HttpClient) {}
isLoggedIn() {
return this.user != null;
}
isAdmin() {
return this.user.isAdmin;
}
unLoggin() {
this.user = null;
}
login(username: string, password: string) {
this.id = null;
this.http.get<number>(`${this.usersurl}/verify?username=${username}&password=${password}`).subscribe(id => this.id = id);
alert(this.id);
if (this.id != null) {
return true;
} else {
return false;
}
}
}
It alert [object Object] localhost:8080/api/users/verify returns for example 8 only 8 no json formated 8