angularjsangular-servicesngresource

Fetch .json with AngularJS $resource


So I have a web server that is handling my .json files.

On the client side a have a simple service :

var service = angular.module('services.service', ['ngResource']);

service.factory('Service', ['$resource',

    function($resource){
        return $resource('json/:serviceId.json', {},
            {

            }
        );

    }
]);

but when I call it from the controller :

$scope.service = Service.get({serviceId : id} );

I don't get anything written into the $scope.service

I've checked my network, and the .json file arrives, but is not handled?

Don't know what to do


Solution

  • The JSON could be malformed. You can look at the response from the call in more detail by logging it:

    Service.get({serviceId: id}).$promise['finally'](console.log);