【发布时间】:2020-11-05 00:15:34
【问题描述】:
您好,我从角度开始,我不知道为什么这没有任何帮助。
很简单,我发出一个get请求,我尝试保存数据,但我做不到,我给你看代码。
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class ProfileComponent implements OnInit {
userinfo;
constructor(private readonly http: HttpClient) {
}
ngOnInit(): void {
this.http.get<any>('/api/v0/user/userinfo?username=test').subscribe(data => {
this.userinfo= data;
});
console.log("get: " + this.getuser);
}
}
这是我从浏览器看到的请求中得到的json
{"id":2,"username":"test","email":"test@test.com"}
但控制台显示的是
get: undefined
帮助!
【问题讨论】:
-
这是控制台行console.log("get:" + this.userinfo);
标签: angular get httprequest