2017-04-13 114 views
0

在我的應用程序,我需要與服務器的REST API連接,所以我已經決定使用這一個:https://github.com/mgonto/restangular但是當我嘗試將其加載到我的模塊:AngularJS加載REST API服務

var app = angular.module('onboarding',['ngRoute','ngSanitize','ngStorage','restangular']); 

我得到這個錯誤:

Failed to instantiate module restangular due to: 
Error: [$injector:nomod] 
http://errors.angularjs.org/1.6.2/$injector/nomod?p0=rest... 
at http://localhost:3000/scripts/angular.min.js:6:425 
at http://localhost:3000/scripts/angular.min.js:25:399 
at b (http://localhost:3000/scripts/angular.min.js:24:439) 
at http://localhost:3000/scripts/angular.min.js:25:173 
at http://localhost:3000/scripts/angular.min.js:41:117 
at q (http://localhost:3000/scripts/angular.min.js:7:351) 
at g (http://localhost:3000/scripts/angular.min.js:40:476) 
at http://localhost:3000/scripts/angular.min.js:41:134 
at q (http://localhost:3000/scripts/angular.min.js:7:351) 
at g (http://localhost:3000/scripts/angular.min.js:40:476 

在GitHub上的文件上寫着,只有1.0.X和1.5.X版本之間的支持。因爲我使用1.6.2版本可能是問題所在。但是當我將版本更改爲1.5.9時,我得到的錯誤完全相同。

與我的代碼或這個庫的錯誤?有沒有人有角度版本巧合類似的錯誤?

+0

您能否提供一些代碼片段?並且請確保您已經添加了所需的js文件以獲得重新安裝。另外,請將其作爲主模塊中的依賴項包含在內。 –

+0

當然!我編輯了我的代碼。 – andrzej541

+0

restangular應該在1.6.2中正常工作;至於你得到的錯誤,通常發生在你的腳本沒有包含在HTML中,或者它們的順序錯誤時。你可以使用'angular.js'而不是'angular.min.js'來獲得更具描述性的錯誤信息。 – Claies

回答

2

我想這就是原因:Restangular取決於angularangular-resourceunderscore。如果您的參考文獻中沒有Underscore.js,請將其添加並再次進行測試。

這在文檔中沒有明確提及。您也可以使用Lodash來達到此目的。

+0

是的。現在它工作正常。我的錯。謝謝你解決我的問題! – andrzej541

+0

我很高興我幫你解決了這個問題。 –

1

restangular未安裝在您的項目中,或者您尚未導入restangular

您是否已將它們導入索引頁?

<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.js"></script> 
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script> 
+0

是的,我做到了。現在我也看到這個錯誤來自jquery-3.1.1.min.js:2。所以也許有jQuery和restangular之間巧合的問題? – andrzej541