Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 567
user2702379 Avatar asked Aug 21 '13 08:08

user2702379


2 Answers

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

like image 148
luacassus Avatar answered Oct 20 '22 10:10

luacassus


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']).  
like image 31
Nils Larson Avatar answered Oct 20 '22 10:10

Nils Larson