Error: Unknown provider: $resourceProvider <- $resource <- myservice AngularJS services

21,300

Solution 1

You have to include angular-resource.js file and load ngResource module: angular.module('app', ['ngResource'])

For more details check "Installation" section inside the documentation for the $resource service: http://docs.angularjs.org/api/ngResource.$resource

Solution 2

The service module also require the resource.

 angular.module('myApp.services',[])

should be

 angular.module('myApp.services',['ngResource'])

and also the controller needs to know about your service-module

angular.module('myApp.controllers', [])

to

angular.module('myApp.controllers', ['myApp.services','myApp.filters', 'myApp.directives'])

and techincally, your motherModule does not require myApp.services only the myApp.controllers

angular.module('myApp', ['myApp.services','myApp.filters', 'myApp.directives' 'myApp.controllers']).  

to

angular.module('myApp', ['myApp.controllers']).  
Share:
21,300

Related videos on Youtube

user2702379
Author by

user2702379

Updated on July 09, 2022

Comments

  • user2702379
    user2702379 almost 2 years

    I am getting this error and I tried different methods, but still I have not found any solution.
    This is my code:

    services.js

    angular
    .module('myApp.services',[])
    .service('myservice', function($resource) {
    
      var pendings = $resource('myUrl2', {methode: 'GET', isArray:true});
      var items; 
    
      var myPo='rawad al bo3bo3';
      var quantity;
      var barcode;
    
      return {
        getItems: function() {
          items = $resource('myUrl', {methode: 'GET', isArray:true});
    

    And this is my controllers:

    angular
    .module('myApp.controllers', [])
    .controller('ReceiveCtrl', ['$scope','myservice', function ($scope,myservice) {      
    

    html:

    <html lang="en" ng-app="myApp">
      <head>
        <meta charset="utf-8">
        <title>My AngularJS App</title>
        <!-- <link rel="stylesheet" href="lib/primeUI/prime-ui-0.9.5.css"> -->
      </head>
      <body>
    
        <ul class="menu">
          <li><a href="#/Receive">view1</a></li>
          <li><a href="#/Pending">view2</a></li>
        </ul>
    
        <div ng-view></div>
    
      </body>
    </html>
    

    In the controller I can't access the variable coming from my services... so the alert message won't work and I get this error

    Error: Unknown provider: $resourceProvider <- $resource <- myservice
    
  • user2702379
    user2702379 over 10 years
    so here i have a small problem since i am new to angular... the file angular-resource.js is present in folder angular... but how to load it? could u help me with it if u may?
  • luacassus
    luacassus over 10 years
    just require it as regular javascript file inside index.html page ;)
  • user2702379
    user2702379 over 10 years
    well this is getting odd since am getting the same error... Error: Unknown provider: $resourceProvider <- $resource <- myservice i will edit my question and add the html file
  • ty.
    ty. over 10 years
    Include from CDN: <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular‌​-resource.js"></scri‌​pt>