I've built 2 factories for my 2 data types Act and Scene. Everything works perfectly except my Scene's update function (create, read, delete work fine). For the life of me i cannot figure out what the Scenes-update function is not working, i just get this message:
TypeError: Object function Resource(value){
copy(value || {}, this);
} has no method 'update'
at Object.ScenesUpdateCtrl.$scope.save
I've got 2 factories:
app.factory('ActsService', function($resource) {
return $resource('/api/acts/:id', {id: '@id'}, {update: {method: 'PUT'}});
});
app.factory('ScenesService', function($resource) {
$resource('/api/scenes/:id', {id: '@id'}, {update: {method: 'PUT'}});
$resource('/api/scenes/:actId', {actId: '@id'}, {query: {method: 'GET', isArray: true}});
$resource('/api/scenes/:actId/:id', {actId: '@actId', id: '@id'}, {get: {method: 'GET'}});
return $resource('/api/scenes/:actId/:id', {actId: '@actId', id: '@id'}, {delete: {method: 'DELETE'}});
});
And some controllers to handle all the Update operations.
function ActsUpdateCtrl ($scope, $location, $routeParams, ActsService) {
var id = $routeParams.id
$scope.act = ActsService.get({id: id})
$scope.action = "Update"
$scope.save = function() {
ActsService.update({id: id}, $scope.act, function() {
$location.path('/admin/acts')
})
}
}
function ScenesUpdateCtrl ($scope, $location, $routeParams, ScenesService) {
var id = $routeParams.id
var actId = $routeParams.actId
ScenesService.get({actId: actId, id: id}, function(resp){
$scope.scene = resp
$scope.actId = resp.PartitionKey
$scope.prev = resp.prev.split(",")
})
$scope.scenes = ScenesService.query({actId: actId})
$scope.action = "Update"
$scope.save = function() {
$scope.scene.prev = $scope.prev
ScenesService.update({id: id}, $scope.scene, function() {
$location.path('/admin/acts/' + $scope.actId)
})
}
}
Act works, Scene throws the before mentioned error message.
Figured it out. AngularJS - creating a service object
Found a way to write it, so that it works, not sure why it works, but as along as it works i'm happy.
app.factory('ScenesService', function ($resource) {
return $resource('/api/scenes/:actId/:id', { actId : '@actId', id:'@id' }, {
update: {method: 'PUT'},
query: {method: 'GET', isArray: true},
get: {method: 'GET'},
delete: {method: 'DELETE'}
})
});