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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18352778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:24:40  来源:igfitidea点击:

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

javascripthtmlangularjsservicecontroller

提问by user2702379

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

我收到此错误并尝试了不同的方法,但仍然没有找到任何解决方案。
这是我的代码:

services.js

服务.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

回答by luacassus

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

您必须包含angular-resource.js文件和加载ngResource模块:angular.module('app', ['ngResource'])

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

有关更多详细信息,请查看$resource服务文档中的“安装”部分:http: //docs.angularjs.org/api/ngResource.$resource

回答by Nils Larson

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']).