JamTay317 JamTay317 - 7 days ago 4
AngularJS Question

Angularjs API call to different action

I am pretty new to AngularJs, so forgive me for not knowing this.
What I am trying to do:
I am trying to call an api with a different method name.
I have seen a lot about $resource,
however i don't understand it.

So the method I am trying to call:

[Route("api/regions/{id?}"), Authorize]
[HttpGet]
public IEnumerable<Region> GetRegionsByStateId(Guid id)
{
var regions = _repository.Get();
return regions.Where(x => x.StateId == id);
}


I have tried
$http.get('api/regions/'+stateId)

which doesnt work, can someone either explain the $resource a little better to me ot tell me why this doesnt work.

Answer

try this

    [Route("api/regions/{id}"), Authorize]
    [HttpGet]
    public IEnumerable<Region> GetRegionsByStateId(Guid id)
    {
        var regions = _repository.Get();
        return regions.Where(x => x.StateId == id);
    }