gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:05:54 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com