I am attempting to utilize Angular and API services to populate data from my database.
Here is my code snippet:
$http.get("/api/trips")
.then(function (response) {
angular.copy(response.data, vm.trips);
}, function (error) {
vm.errorMessage = "Failed to load data: " + error
});
Here is the API GET()
method:
[HttpGet("")]
public IActionResult Get()
{
var results = _repository.GetTripsByUsername(this.User.Identity.Name);
return Ok(Mapper.Map<IEnumerable<TripViewModel>>(results));
}
Currently, I am facing an issue where no data is displaying. I suspect the error may be due to this.User.Identity.Name
being passed incorrectly, but I am unsure.
Interestingly, when I change the method from GetTripsByUsername
to GetAllTrips
, which retrieves all trips without any filters, the data displays properly on the page.
The function itself works fine. When I test it using PostMan, it recognizes my cookie and returns the correct trips. However, on the webpage, it does not work as expected.