My angular.js application includes a productsCtrl.js file that displays the following controller:
app.controller('ProductsCtrl', ['$scope', 'Api', function($scope, Api) {
$scope.products = Api.Product.query();
//Delete Product
$scope.deleteProduct = function(productId, idx) {
Api.Product.remove({productId: productId});
$scope.products.splice(idx, 1);
};
}]);
Furthermore, I have an Api factory:
app.factory('Api', ['$resource', function($resource) {
return {
Product: $resource(
'/api/products/:productId',
{productId: '@productId'},
{'query': {method: 'GET', isArray: false }}
),
Item: $resource(
'/api/items/:itemId',
{itemId: '@itemId'}
)
};
}
]);
After changing
$scope.products = Api.Product.get();
and trying the splice method, an error message is displayed: TypeError: Object #<Resource> has no method 'splice'
.
On the other hand, keeping the original code as displayed above but setting isArray to true results in the following error:
Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object