I have a json object of arrays that looks like this:
[
{
"id": 1,
"name": "John Smith",
"age": 52
},
{
"id": 2,
"name": "Jane Walters",
"age": 43
},
{
"id": 3,
"name": "Mike Wilson",
"age": 65
},
{
"id": 4,
"name": "Tom Samuels",
"age": 29
}
]
I am displaying all these names on the "index" page, and I want to show only one on each of the "character/[id]" pages. Here is my controller for the index page:
angular.module('myApp.controllers', []).
controller('index', ['$scope', 'characters', function($scope, c){
$scope.characters = c.getCharacters;
}]);
Aaand here's the "characters" service:
factory('characters', function($resource){
return $resource('JSON/characters.json', {},
{
'getCharacters': {method: 'GET', isArray:true}
});
});
The views are the standard boilerplate.
My problem is, how do I create a service (or manipulate the object in the controller) for the "character/[id]" route so it only selects a single array based on the JSON id?
I did the phonecat demo on angularjs.org, but that demo uses separate JSON files for each phone, and then one big JSON file for the index page. I want to avoid that.
One final thing: I am using angular-seed, so I'd like to maintain the syntax used there. I've tried lots of different approaches with no luck.