2016-05-17 93 views
0

我想为$ REST API调用使用$资源,但我得到的错误以下。

Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to: 
Error: [$injector:modulerr] Failed to instantiate module starter.services due to: 
Error: [$injector:modulerr] Failed to instantiate module $resource due to: 
Error: [$injector:nomod] Module '$resource' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 
http://errors.angularjs.org/1.5.3/$injector/nomod?p0=%24resource 
    at http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:13438:12 
    at http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:15404:17 
    at ensure (http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:15328:38) 
    at module (http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:15402:14) 
    at http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:17894:22 
    at forEach (http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:13691:20) 
    at loadModules (http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:17878:5) 
    at http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:17895:40 
    at forEach (http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:13691:20) 
    at loadModules (http://localhost:8080/stockpicker/stockPickerApp/www/lib/ionic/js/ionic.bundle.js:17878:5) 
下面

是我的index.html其中i已包括angular.js和角度resouce.js

<script src="lib/ionic/js/ionic.bundle.js"></script> 
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script> 
<script type="text/javascript" src="lib/ionic/js/angular/angular-resource.js"></script> 

<script src="js/app.js"></script> 
<script src="js/controllers.js"></script> 
<script src="js/services.js"></script> 
</head> 
<body ng-app="starter"> 
... 
... 
下面

是从我app.js

angular.module('starter', [ 'ionic', 'ionic.service.core', 'starter.controllers', 'starter.services','ngResource']) 

.run(function($ionicPlatform) { 

内容的内容from service.js

angular.module('starter.services', ['$resource']).factory('StockPickerService', function($http,$resource) { 
// Might use a resource here that returns a JSON array 

A我错过了什么?

回答

2

Inject ngResource in module starter.services,not $resource

angular.module('starter.services', ['ngResource']).factory('StockPickerService', function($http,$resource) { 
// Might use a resource here that returns a JSON array 
1

ngResource是提供$resource服务模块。

所以

angular.module('starter.services', ['ngResource']).factory('StockPickerService', function($http,$resource) { } 

应该工作