[英]What does http.get return and how to convert it to an object
我的组件中有这种方法
GetInfo(id)
{
const data = this.http.get(this.baseUrl + "api/SampleData/EditMake/" + id);
console.log(data);
}
它只是运行http.get到Web api控制器方法。 返回一个对象。
[HttpGet]
[Route("api/[Controller]/EditMake/{id:int}")]
public IActionResult EditMake(int id)
{
return Ok(_vehicleService.GetMakeById(id));
}
那是有问题的方法。 问题是,数据不是EditMake方法返回的类型的对象。 我想念什么?
需要订阅HTTP请求。 Http请求返回一个可观察对象作为响应,为了访问数据,我们需要订阅该可观察对象。
GetInfo(id) {
let data;
this.http.get(this.baseUrl + "api/SampleData/EditMake/" + id).subscribe((response) => {
data = response;
console.log(data);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.