在我的angularjs应用程序上获取以下消息:
Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- Item
http://errors.angularjs.org/1.3.8/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20Item
at http://localhost:49717/Scripts/angular.js:63:12
at http://localhost:49717/Scripts/angular.js:3994:19
at Object.getService [as get] (http://localhost:49717/Scripts/angular.js:4141:39)
at http://localhost:49717/Scripts/angular.js:3999:45
at getService (http://localhost:49717/Scripts/angular.js:4141:39)
at Object.invoke (http://localhost:49717/Scripts/angular.js:4173:13)
at Object.enforcedReturnValue [as $get] (http://localhost:49717/Scripts/angular.js:4035:37)
at Object.invoke (http://localhost:49717/Scripts/angular.js:4182:17)
at http://localhost:49717/Scripts/angular.js:4000:37
at getService (http://localhost:49717/Scripts/angular.js:4141:39) <div ng-view="" class="ng-scope">
我的app.js
'use strict';
var SalesApp = angular.module('SalesApp', ['ngRoute']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', { controller: ItemCtrl, templateUrl: 'item.html' }).
otherwise({ redirectTo: '/' });
}]);
SalesApp.factory('Item', function ($resource) {
return $resource('/api/Item/:iid', { iid: '@iid' }, { update: { method: 'PUT' } });
});
var ItemCtrl = function ($scope, $location, Item) {
$scope.items = Item.query();
};
我加载的脚本
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-resource.js"></script>
<script src="Scripts/app.js"></script>
<script src="Scripts/angular-resource.js"></script>
<script src="Scripts/angular-sanitize.js"></script>
<script src="Scripts/angular-animate.js"></script>
<script src="Scripts/angular-touch.js"></script>
<script src="Scripts/angular-route.js"></script>
无法弄清楚可能出现的问题?为了简单起见,我将ItemCtrl保存在app.js文件中,不知道我会怎么做呢?
答案 0 :(得分:15)
您需要将其列为依赖项,因为$ resource服务未与主Angular脚本捆绑在一起。将其包含在HTML页面中后,可以将其包括在内:
var SalesApp = angular.module('SalesApp', ['ngRoute','ngResource']).