Currently, I am using json files to stub my $http.get() calls. I am trying to retrieve a specific subset of the json file in my angular controller. Despite looking at other solutions that recommend setting a params property in the Get call, it does not seem to be working for me.
Below is the snippet of my controller code:
angular.module('agileApp')
.controller('projectController', ['$scope', '$filter', '$http','$routeParams', function($scope, $filter, $http, $routeParams){
$http.get('json/testData.json').success(function(data){
//console.log(data);
$scope.projectData = $filter('filter')(data.projectDetail, {Id:1})[0];
console.log($scope.projectData);
});
}]);
This is an excerpt from my json file:
{ 'projectDetail': [{
'Id': 1,
'projectName': 'Project1',
'projectStatus': 'In Progress',
'teamMembers': ['User1,'User2', 'User3'],
'userStories': [
{'userStoryId': 0,
'Description': 'As a user blah blah blah 1',
'storyPoints': 10
},
{'userStoryId': 1,
'Description': 'As a user blah blah blah 2',
'storyPoints': 10
},
{'userStoryId': 2,
'Description': 'As a user blah blah blah 3',
'storyPoints': 10
},
{'userStoryId': 3,
'Description': 'As a user blah blah blah 4',
'storyPoints': 10
},
{'userStoryId': 4,
'Description': 'As a user blah blah blah 5',
'storyPoints': 10
},
{'userStoryId': 5,
'Description': 'As a user blah blah blah 6',
'storyPoints': 10
},
]
},
The project detail array contains multiple objects, but I only need to fetch the one where Id matches the routeID parameter passed into the controller.
I would greatly appreciate any assistance on this matter. Thank you!