Search code examples
angularjsangular-resource

Angular JS using $resource throwing error : Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- MyController


I am getting the error "Unknown Provider". I have searched throught the forums and implemented all suggestions(marked as answer, as well). But error isnt resolved. Please guide. Below is the code:

In html, am referring 1. angular.min.js 2.angular-resource.js 3.App.js 4.MyJS in the same order.

In my app.js:

angular.module('myApp', [ 'ngSanitize', 'ngCookies','ngResource'  ]);

angular.module('myApp')    
.controller('MainCtrl', ['$rootScope','$resource', function($rootScope) {
     //my code goes here//
       }]);

In another JS file:

angular.module('myApp')
.controller('myController', 
['$scope', '$rootScope', '$http', '$window', '$cookies', '$resource', function ($scope, $rootScope, $http, $window, $cookies, $resource) 
{ ---- My Code -----    }

I have seen the forums and suggestions and ensured app.js is called first. angular-resource.js is referred after referring angular.min.js.

Please suggest where am going wrong.

Thank You


Solution

  • Should be

    ['$rootScope','$resource', function($rootScope, $resource) {
    

    instead of

    ['$rootScope','$resource', function($rootScope) {
    

    Number of controllers function parameters should be same as number of string literals.