I think because you don’t have a copy yet. You will need to do this:
$scope.products = new Product();
$scope.products.all()
Another option is to define the all () method at the service level. Instead of adding to the prototype, which is only available after the new Product (), you can change it as:
app.factory('Product',function ($resource,$cacheFactory) {
var Product = $resource('/the/url/:id', {id: '@id'}),
cache = $cacheFactory('Product'),
products;
Product.all = function(){
products = cache.get('all');
if(typeof products == 'undefined'){
products = Product.query();
cache.put('all',products);
}
return products;
};
Product.prototype.$all = function () {
Product.all.call(this);
}
return Product;
})
This way you will have Product.all () for the resource and product. $ all () for instances.