Having trouble with using a JSON file as a variable in a factory.
I am using two factories to serve two controllers: dierService + dierDetailService
The dierService factory is working fine and the dierenCtrl is listing all the JSON content like it should.
But I can seem to be able to replace the dieren varibale inside the dierDetailService factory without breaking it!
How can I use the JSON file (http://hetwikkie.nl/dieren.json) in the dierDetailService factory?
.factory('dierService', function($http) {
var url="http://hetwikkie.nl/dieren.json";
var dierenData = function(){
return $http.get(url);
}
return {
getData: dierenData
}
})
.factory('dierDetailService', function($http) {
var dieren = [
{
"title": "Querney",
"id": "0",
"diersoort": "Schaap",
"description": "Dit is Querney, één van onze gecastreerde rammen. Je herkent hem aan zijn gevlekte kop!"
},
{
"title":"Suske",
"id": "1",
"diersoort": "Schaap",
"description": "Dit is Suske, één van onze gecastreerde rammen. Je herkent hem aan zijn gevlekte kop!"
}
];
return {
all: function() {
return dieren;
},
get: function(dierId) {
return dieren[dierId];
}
}
})