Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown provider: $resourceProvider - AngularJS

Getting the following message on my angularjs app:

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

Scripts that I load

<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 possibly have gone wrong? For the sake of simplicity I'm keeping the ItemCtrl in the app.js file, don't know how I would do it otherwise?

like image 965
btmach Avatar asked Dec 05 '22 23:12

btmach


1 Answers

you need to list it as an dependency as the $resource service doesn’t come bundled with the main Angular script. After including it in your HTML page it can be included like:

 var SalesApp = angular.module('SalesApp', ['ngRoute','ngResource']).
like image 180
A.B Avatar answered Dec 21 '22 07:12

A.B