【发布时间】:2016-11-20 12:18:33
【问题描述】:
我定义了一个基本的 ngResource:
angular.module('factories', []).factory('SeedSource', [
'$resource', function($resource) {
return $resource('/seed-sources/:id/', {
id: '@id'
}, {
update: {
method: 'PUT'
}
});
}
]);
在我的控制器中,我希望能够从局部变量而不是传统的 .query() 方法填充此资源的列表,例如:
$scope.seed_sources = json_array_of_seed_sources;
这一直有效,直到我需要调用一个 ngResource 方法,例如:
seed_source.$save()
我知道我可以走很长的路,只需将每个项目单独添加到 $scope.seed_sources,每个作为 new Seeder(...),但我希望可能有一种更清洁的方法来实现这一点?
【问题讨论】:
标签: angularjs ngresource