当我试图调用我的服务时,我得到了‘不是一个函数’错误。NgResource已经被注射了。我做错了什么?
controller.js:
app.controller('controllerA', ['$scope', 'CustomizingService',
function($scope, CustomizingService) {
$scope.cust = CustomizingService.Customizing.squares({numberOf: 2, valid: true});
}]);service.js:
(function () {
angular.module('ST_CCG').factory('CustomizingService', ['$resource', function ($resource) {
//var url = config.CustomizingAPI_Url + '/Customizing/:link/';
var url = 'http://localhost:54483/BusinessService.svc/:link/';
return {
Customizing: $resource(url, {
squares: {
method: 'GET',
params: { link: 'GetSquares', numberOf: '@numberOf', valid: @valid },
isArray: true },
circles: {
method: 'GET',
params: { link: 'GetCircles', valid: true },
isArray: true }
})
};
}]);
})();编辑
我正在使用chrome调试器并得到以下错误: TypeError: CustomizingService.Customizing.orders不是一个函数
app.js:
var app = angular.module('ST_CCG', [
'ngRoute',
'ngResource'
])
.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/menu', {
templateUrl: 'Modules/Menu/view.html',
controller: 'controllerA'
}).
when('/orders', {
templateUrl: 'Modules/Orders/view.html',
controller: 'controllerB'
}).
otherwise({
redirectTo: '/'
});
}
]);index.html:
...
<!--MODOLE + CONTROLLER Resources-->
<script src="app.js"></script>
<script src="service.js"></script>
<script src="modules/menu/controller.js"></script>
<script src="modules/orders/controller.js"></script>
</head>
<body ng-app="ST_CCG">
<a href="#/menu">Menu</a>
<a href="#/orders">Orders</a>
<div ng-view></div>
</body>发布于 2015-05-21 10:59:32
这可能是因为你把你的动作传递到默认参数的位置。把它改成
Customizing: $resource(url, {valid: true}, {
squares: // etc我使用valid: true作为默认参数,因为您似乎在这两个操作中都使用了它。
https://stackoverflow.com/questions/30371561
复制相似问题