I have this method in my component
GetInfo(id)
{
const data = this.http.get(this.baseUrl + "api/SampleData/EditMake/" + id);
console.log(data);
}
It just runs a http.get to a web api controller method. Which returns an object.
[HttpGet]
[Route("api/[Controller]/EditMake/{id:int}")]
public IActionResult EditMake(int id)
{
return Ok(_vehicleService.GetMakeById(id));
}
That is the method in question. Problem is, data isn't an object of the type which the EditMake method returns. What am i missing?
Need to subscribe to the HTTP request. Http request return an observable as a response and in order to access the data, we need to subscribe to the observable.
GetInfo(id) {
let data;
this.http.get(this.baseUrl + "api/SampleData/EditMake/" + id).subscribe((response) => {
data = response;
console.log(data);
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.