Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create simple "database" in json file, and service for it with function to get specific item from json parsed array. I'm using sample modified code from angular tutorial:

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

projectService.factory('Project', ['$resource', '$http',
function($resource, $http){
    return $resource('assets/data/projects.json', {id: '@id'}, {
        get: {
            method: 'GET',
            transformResponse: function(data) {
                //problem
            }
        }
    });
}]);

I see that correct parameter is passed during ajax call the whole contect of json file is returned, and I cannot access the url param to filter the array to get correct object. Is there any way to access url params in transformResponse function?

share|improve this question
    
The second argument in the $resource provider, paramDefaults, is designed to contain the default URL parameters for parameters states in the first argument, the url. Your URL does not have an :id parameter in it, so in all cases it will just return the whole JSON object. –  horyd 22 hours ago
    
@horyd - yeah, I know that passing parameter to url containing only json file will always return the whole content of the file, and I just want to filter the content of the file manually, but I can't get the url parameters I passed with the request, cause I see that the parameter is correctly passing into request e.g: build/assets/data/projects.json?id=projectId –  Marrbacca 33 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.