简体   繁体   English

错误:未知提供者:$ resourceProvider < - $ resource < - myservice AngularJS服务

[英]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 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:

<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

You have to include angular-resource.js file and load ngResource module: angular.module('app', ['ngResource']) 你必须包括angular-resource.js文件并加载ngResource模块: angular.module('app', ['ngResource'])

For more details check "Installation" section inside the documentation for the $resource service: http://docs.angularjs.org/api/ngResource .$resource 有关更多详细信息,请查看$resource服务文档中的“安装”部分: http//docs.angularjs.org/api/ngResource。$ resource

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 而且从技术上来说,你的motherModule不需要myApp.services只需要myApp.controllers

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

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM