我们构建了一个控制器,其中包含应用程序的所有$ resource,以便于从控制器进行更轻松的访问:
app.controller('ResourcesCtrl', ['$scope', '$resource', '$controller', function ($scope, $resource, $controller) {
$scope.Product = $resource(resources_url_global + '/products/:id.json', { id: '@id' }, default_actions);
var default_actions = {
'get': {
method: 'GET'
},
'create': {
method: 'POST'
},
'save': {
method: 'POST'
},
'update': {
method: 'PUT'
},
'update_all': {
method: 'PUT'
},
'query': {
method: 'GET',
isArray: true
},
'remove': {
method: 'DELETE'
},
'delete': {
method: 'DELETE'
}
};}]);
以及来自其他控制器的访问示例:
app.controller('ProductsManagementCtrl', ['$scope', '$controller', '$resource',
function ($scope, $controller, $resource) {
$controller('ResourcesCtrl', {$scope: $scope}); // inherit Parent Controller }]);
问题是我想从工厂使用那个ResourceCtrl,但是我不知道如何从工厂调用它。
您应该将其构建为service
而不是controller
。
您可以将服务注入otherservices
和other中controllers
。
如果您确实需要,resource controller
则只需注入resource service
并创建一个包装器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句