未知提供者:AngularJS中的$ resourceProvider< - $ resource

时间:2017-06-18 14:01:01

标签: javascript angularjs

如标题所述,我收到以下错误: 未知提供者:$ resourceProvider< - $ resource。

特别是在Microsoft Edge的控制台中:

SCRIPT438: Object doesn't support property or method 'info'

angular-resource.js (444,1)

Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- Review
http://errors.angularjs.org/1.6.1/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20Review
at Anonymous function (https://code.angularjs.org/1.6.1/angular.js:4630:13)
at getService (https://code.angularjs.org/1.6.1/angular.js:4783:11)
at Anonymous function (https://code.angularjs.org/1.6.1/angular.js:4635:13)
at getService (https://code.angularjs.org/1.6.1/angular.js:4783:11)
at injectionArgs (https://code.angularjs.org/1.6.1/angular.js:4807:9)
at invoke (https://code.angularjs.org/1.6.1/angular.js:4834:7)
at enforcedReturnValue (https://code.angularjs.org/1.6.1/angular.js:4676:7)
at invoke (https://code.angularjs.org/1.6.1/angular.js:4842:9)
at Anonymous function (https://code.angularjs.org/1.6.1/angular.js:4636:13)
at getService (https://code.angularjs.org/1.6.1/angular.js:4783:11) <div class="ng-scope" ng-view="">
angular.js (14328,11)

我搜索了这个错误并遇到了多个解决方案,但即使在尝试实施所述解决方案时,我似乎还在做错事......

的index.html:`

<!DOCTYPE html>

<html ng-app="VideogameReviewsApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello AngularJS</title>

</head>

<body>
    <div ng-view></div>
    <script src="https://code.angularjs.org/1.6.1/angular.js"></script>
    <script src="https://code.angularjs.org/1.6.1/angular-route.js"></script>
    <script src="https://code.angularjs.org/1.6.4/angular-resource.js"></script>
    <script src="js/app.js"></script>
</body>

</html>

为简单起见,我在app.js中包含了所有代码:

'use strict';

var VideogameReviewsApp = angular.module('VideogameReviewsApp', ['ngRoute','ngResource']).
     config(['$routeProvider', function ($routeProvider) {
        $routeProvider.
            when('/', { controller: ReviewCtrl, templateUrl: 'review.html' }).
            otherwise({ redirectTo: '/' });
     }]);

VideogameReviewsApp.factory('Review', function ($resource) {
    return $resource('http://localhost/videogamereviews/review/:id', { id: '@id' }, { update: { method: 'PUT' } });
});

var ReviewCtrl = function ($scope,Review) {
    alert("mop")
    $scope.items = Review.get();
};

非常感谢您的帮助!

阿什利

1 个答案:

答案 0 :(得分:0)

更新角度资源引用以匹配角度版本。

  <script src="https://code.angularjs.org/1.6.1/angular-resource.js">

<强>样本

&#13;
&#13;
angular.module('VideogameReviewsApp', ['ngRoute','ngResource'])
.controller("testctrl",function($scope){
$scope.appname = "resourceTest";
})
&#13;
<!DOCTYPE html>
<html ng-app="VideogameReviewsApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello AngularJS</title>
</head>

<body ng-controller="testctrl">     

{{appname}}
    <script src="https://code.angularjs.org/1.6.1/angular.js"></script>
    <script src="https://code.angularjs.org/1.6.1/angular-route.js"></script>
    <script src="https://code.angularjs.org/1.6.1/angular-resource.js"></script>
</body>
</html>
&#13;
&#13;
&#13;