我已经按照示例进行了操作,但是在将自定义方法添加到资源的原型时显然出现了问题。
app.factory('Product',function ($resource,$cacheFactory) {
var Product = $resource('/the/url/:id', {id: '@id'}),
cache = $cacheFactory('Product'),
products;
Product.prototype.all = function(){
products = cache.get('all');
if(typeof products == 'undefined'){
products = Product.query();
cache.put('all',products);
}
return products;
};
return Product;
})
在控制器中我做了,$scope.products = Product.all();
但我得到了
TypeError: Object function Resource(value) {
copy(value || {}, this);
} has no method 'all'