2016-05-17 77 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) { } 

應該工作