I'm very new to angular, and I'm not understanding why the resource is not working as expected. When I was using the $http.get() request, I could assign it to a variable 'data', and use data.key to get the value. This doesnt seem to work with my current resource setup, I get an error saying "TypeError: Cannot read property '0' of undefined", this wasn't an issue before.
myAppServices.factory('Apprentice',['$resource', function($resource){
return $resource('javascripts/:apprenticeId/.json', {} ,{
query: { method:'GET', params : {apprenticeId : 'apprentices'}, isArray:true}
});
}]);
and the controller....
myAppControllers.controller('apprenticeCtrl',['$scope', 'Apprentice',
function($scope, Apprentice) {
var data = Apprentice.query();
$scope.mainImageUrl = data.images[0];
var index = data.images.indexOf($scope.mainImageUrl);
$scope.setImage = function() {
(index == data.images.length - 1) ? index= 0 : index++;
$scope.mainImageUrl = data.images[index];
};
}]);