html - 相关服务和 Controller AngularJS 错误 : Unknown provider: myservicesProvider <- myservices

标签 html angularjs service controller

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

app.js

    angular.module('myApp', [ 'myApp.services','myApp.filters', 'myApp.directives',
     'myApp.controllers']).          
     config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/Receive', {templateUrl: 'partials/partial1.html', controller: 'ReceiveCtrl'});
$routeProvider.when('/Pending', {templateUrl: 'partials/partial2.html', controller: 'PendingCtrl'});
 $routeProvider.when('/ResumePending', {templateUrl: 'partials/partial3.html', controller: 'PendingCtrl'});
$routeProvider.otherwise({redirectTo: '/view1'});
 }]);

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});
                return items  ;  
                  },



              setQty: function(qty){
                 quantity=qty;
                 },


 deletePO : function(id){
                },


suspend:function(id){
    //URL needed
},




       }).
      value('version', '0.1');

这是我的 Controller :

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


   $scope.po='rawad';
   alert ('WoW!! It is '+myservice.getPO);
 $scope.quantity='';
 $scope.barcode='';



   $scope.addProduct= function(){

    myservice.setQty($scope.quantity);
    myservice.setBc($scope.barcode);
    myservice.addToPliste;

      };

        }]);

在 Controller 中,我无法访问来 self 的服务的变量...所以警报消息不起作用,我收到此错误

Error: Unknown provider: myservicesProvider <- myservices

最佳答案

服务声明:

angular.module('myApp.services',[]).
    service('myservice',function($resource)

Controller 中的服务注入(inject):

angular.module('myApp.controllers', []).
    controller('ReceiveCtrl', ['$scope','myservices', ...

该服务名为myservice,但您在注入(inject)时使用myservices

关于html - 相关服务和 Controller AngularJS 错误 : Unknown provider: myservicesProvider <- myservices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18350608/

相关文章:

mysql - 启动可能与现有服务存在端口冲突的服务

javascript - 鼠标悬停后下拉菜单不会保持静止

javascript - 从回调函数更改模型值

javascript - Material Angular 虚拟重复不在下拉列表中显示值

windows - 应用 Windows 10 Creators Update 后 CouchDB 无法启动

c# - 错误 1054 - 服务未及时响应 - C# 应用程序

html - 在 iOS7 中固定页眉和页脚的网页滚动问题

html - 无法找到删除线的样式

css - 如何为文本设置固定高度和可变宽度

javascript - 在 AngularJS 中使用 ng-repeat 的动态类