簡體   English   中英

編寫指令時有角未定義的外部庫

[英]Angular, undefined external libraries when writing directive

我不確定這是否正是問題所在,但我會盡力弄清楚。 我試圖使用帶有包裝廠的http://codepen.io/amergin/pen/cKAqv示例編寫指令。 因此,我要做的是在應用程序的my / directs目錄中創建一個外部指令,然后將工作指令直接復制到我自己的指令中。 我遇到的問題很刺耳,似乎一點都不喜歡。 我的目錄文件看起來像這樣(為了方便起見,我刪除了內部文件,但實際上與codepen示例相同)

'use strict';

angular.module('demoApp')
.directive('packeryAngular', function($rootScope, $timeout) {
return {
//contents in here
 }

 });

而咕unt聲似乎不喜歡這一點,並且正在返回這個-

app/scripts/directives/packeryangular.js
line 17  col 36  'Packery' is not defined.
line 24  col 32  'Draggabilly' is not defined.
line 37  col 13  '$' is not defined.
line 38  col 15  '$' is not defined.
line 48  col 32  'Draggabilly' is not defined.
line 13  col 38  'attrs' is defined but never used.
line 27  col 62  'pointer' is defined but never used.
line 27  col 55  'event' is defined but never used.
line 27  col 45  'instance' is defined but never used.
line 52  col 62  'pointer' is defined but never used.
line 52  col 55  'event' is defined but never used.
line 52  col 45  'instance' is defined but never used.

因此,我對於這一切還很陌生,並且我不確定要如何處理這些信息。 即使我100%確信庫已加載到主應用程序中,也沒有定義packery和draggabilly可以嗎? 這是說jquery $沒有定義,我在想這是同樣的問題,因為我也確定庫也已加載。 看起來很簡單,所以我不太明白為什么會遇到這些問題。 非常感謝您的幫助,非常感謝您的閱讀!

看起來是jshint結果。

這不是實際的錯誤-js jshint可能檢測到錯誤。

關於“未定義”錯誤-您可以在.jshintrc中定義全局變量,如下所示:

"globals": { "Packery": false, "Draggabilly": false, "$": false }

關於“已定義但從未使用過”-有關在代碼中定義的無用變量的提示(變量已定義但實際上從未使用過-通常可以安全地刪除它)

如果願意,可以通過在.jshintrc中插入"unused": false來禁用此提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM