有人可以帮我从 Angular 5 中的 http 响应中获取数字吗?我现在不知道该怎么做,我在互联网上搜索,但 Angular 增长非常快,所以它对我没有帮助。谢谢你的帮助 !
我的代码:
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;
}
}
}
它警告 [object Object] localhost:8080/api/users/verify 返回例如 8 仅 8 无 json 格式 8