Search code examples
jsonangularjsionic-frameworkngresource

ngResource: Promise not Resolved


Let's say a Service like this:

.factory('GetPaths', function($resource) {
  return $resource('/paths/coord/:lat/:long', 
       {lat: "@lat" }, {long: "@long" } , 
       {
         get:    {method: 'GET' , isArray: true },  
      }

   );
})

it gets called like this:

scope.paths = GetPaths.get({'lat':1},{'long':1}); 

I get the following response:

{"long":1,"$promise":{},"$resolved":false}

When I use cURL on my backend, I get this JSON Array:

[
  {
    "pathid":"1",
    "title":"Pathest",
    "eta":"3:00",
    "TYPE":"Hike",
    "difficulty":"Hard",
    "distance_in_km":"0"
 }
]

My Question is: How to retrieve the same JSON Array as data to populate my list?


Solution

  • There is an issue with $resource configuration. Should be:

    return $resource('/paths/coord/:lat/:long', 
       {lat: '@lat', long: '@long' } , 
       { get: { method: 'GET', isArray: true } }
    );
    

    And in your case you can just use query instead of get and leave out third argument at all. Check out $resource docs.