2013-08-21 78 views
23

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

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}); 

这是我的控制器:

​​

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> 

在控制器我可以不能访问变量com从我的服务荷兰国际集团......这样的警告消息将不工作,我得到这个错误

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

回答

59

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

有关详情,请“安装”部分在$resource服务的文档中:http://docs.angularjs.org/api/ngResource $ resource

+0

所以在这里我有一个小问题,因为我是新来的角...文件角resource.js存在于文件夹角..但是如何加载呢?如果你愿意,你能帮助我吗? – user2702379

+1

只需要它作为index.html页面内的常规javascript文件;) – luacassus

+0

ohh okey:P非常感谢你...愚蠢的问题提问:P – user2702379

14

服务模块也需要该资源。

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

应该

angular.module('myApp.services',['ngResource']) 

和控制器也需要了解你的服务模块

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

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

和techincally,你motherModule不需要myApp.service这仅仅只是一个myApp.controllers

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

angular.module('myApp', ['myApp.controllers']). 
相关问题