I have a simple WebApi created in asp.net core which is as follows:
[HttpGet("GetHomePageData")]
public IActionResult GetHomePageData()
{
HomePageData HomePageData = new HomePageData()
{
BookName = "Test Book",
AddressCount = 55
};
return Ok(HomePageData);
}
In angular, i try to call it as follows:
constructor(public http: Http, @Inject('BASE_URL') public baseUrl: string) {
http.get(baseUrl + 'api/GetHomePageData')
.subscribe(res => this.homePageData = res.json() as HomePageData);
}
In my view, i try to display HomePageData as follows:
<div *ngIf="homePageData">Total Address = {{ homePageData.AddressCount }}</div>
When run in Chrome, the Api call works fine and the page loads fine with no errors. However, no values are displayed, as in the 'homePageData.AddressCount' is empty.
Anybody know what happened here?
FYI, I've followed the SO answer in Observable type error: cannot read property of undefined
Thanks!