2016-04-03 55 views
2

此問題是昨天發佈的Definition for gapi in an Angular controller?的後續行動。ngDrive沒有定義?

用戶pinoyyid向我指出他的混帳回購協議ngDrive(https://github.com/pinoyyid/ngDrive

我工作過戒菸開始跑進一個錯誤,在我的控制檯'ngDrive' is not defined

這是導致此錯誤

angular.module('ngm.ngDrive') 
.provider('OauthService', ngDrive.Config) 
.config(function (OauthServiceProvider) { 
    OauthServiceProvider.setScopes('https://www.googleapis.com/auth/drive.file'); 
    OauthServiceProvider.setClientID('2231299-2bvf1.apps.googleusercontent.com'); 
    OauthServiceProvider.setTokenRefreshPolicy(ngDrive.TokenRefreshPolicy.ON_DEMAND); 
    OauthServiceProvider.setNoAccessTokenPolicy(999);     // 0 = fail, > 0 = retry after x 
}); 

代碼具體的ngDrive.Config

注射服務爲我app.js文件時,如下圖所示

angular 
.module('App', [ 
'ngAnimate', 
'ngCookies', 
'ngResource', 
'ngRoute', 
'ngSanitize', 
'ngTouch', 
'ui.sortable', 
'firebase', 
'angular-toArrayFilter', 
'ngm.ngDrive' 
]) 

我有我沒問題還按指定的方式放置了庫的腳本標記:

<!-- build:js({.tmp,app}) scripts/scripts.js --> 
<script src="bower_components/ngDrive/build/module.js"></script> 
<script src="scripts/app.js"></script> 
<script src="scripts/controllers/login_controller.js"></script> 
<script src="scripts/controllers/view_resources_ctrl.js"></script> 
<!-- endbuild --> 

我不太清楚我在做什麼錯在這裏。我沒有看到指南中可能意外跳過的任何內容。

謝謝你的時間。

回答

0

我做過bower install ngDrive --save,包括<script src="../bower_components/ngDrive/build/module.js"></script>(我的index.js是在一個app文件夾中)在app.js之前,注入了ngm.ngDrive,複製粘貼.provider('OauthService', ngDrive.Config)。然後,我加入到配置,

OauthServiceProvider.setScopes('https://www.googleapis.com/auth/drive.file'); 
OauthServiceProvider.setClientID('2231299-2bvf1.apps.googleusercontent.com'); 
OauthServiceProvider.setTokenRefreshPolicy(ngDrive.TokenRefreshPolicy.ON_DEMAND); 
OauthServiceProvider.setNoAccessTokenPolicy(999); 

沒有抱怨ngDrive.Config。但是,我會收到錯誤消息:

  1. 無法加載資源:服務器迴應的404(未找到)狀態:http://localhost:3000/bower_components/ngDrive/build/module.js.map(用於加載資源,我當時沒有明確要求)
  2. OauthServiceProvider.setNoAccessTokenPolicy不一個函數。 (在'OauthServiceProvider.setNoAccessTokenPolicy(999)','OauthServiceProvider.setNoAccessTokenPolicy'未定義)。 (檢查源和模塊的當前版本中不存在這種方法)

我試過了,但無法重現您的錯誤。

+0

你介意把你的app.js文件放在JsFiddle上。我可能只是有一些可能導致錯誤的地方。 –

+0

我做了一個我的App.js和Index.html文件看起來像JsFiddle https://jsfiddle.net/uoLpmaah/1/ –

+0

看到我的主要答案,行'setNoAccessTokenPolicy'應該被刪除。我已經修復了文檔。 – pinoyyid

0

'ngDrive' is not defined是由module.js未能加載造成的。如果您查看網絡選項卡,您將看到一個404.

此外,文檔中存在一個錯誤,setNoAccessTokenPolicy不再是一項功能,因此您應該刪除該行。版本0.1.10修復了文檔。

+0

''ngDrive'未定義'錯誤未出現在瀏覽器控制檯中,當我將代碼放入並保存時,它出現在我的本地命令行中。 http://puu.sh/o6QxM/5914b30903.png –

+0

錯誤來自jshint?如果是這樣,你可以忽略它。 – pinoyyid