Unknown provider: $ resourceProvider - AngularJS

Getting the following message in my angularjs application:

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">

My 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();
};

The scripts I download

<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>

Can't figure out what could go wrong? For simplicity, I save ItemCtrl in the app.js file, I don’t know how I would do it otherwise?

+4
source share
1 answer

you need to specify it as a dependency since the $ resource service is not included with the main Angular script. After you include it in an HTML page, you can include it as:

 var SalesApp = angular.module('SalesApp', ['ngRoute','ngResource']).
+15
source

Source: https://habr.com/ru/post/1568981/


All Articles