這可能是一個Angular的問題,但我懷疑它與一般的JS更相關。我正在設置一個Angular應用程序,目前它運行良好。JS腳本沒有運行,如果包裹在IIFE(角度)
我已經打破它分成不同的模塊app
,app.core
,app.components
等
我所遇到現在奇數的問題,在這裏我試圖創建一個指示所有模塊使用,我有點難倒在這一個。我能得到這個工作,因爲它應該在我的視圖中顯示模板:
'use strict';
angular.module('app.components')
.directive('navBar', function() {
return {
controller: 'Main',
controllerAs: 'vm',
link: function(){
console.log('Directive link')
},
template: 'Directive template'
};
});
然而,當我把它包在IIFE:
(function() {
'use strict';
angular.module('app.components')
.directive('navBar', function() {
return {
link: function(){
console.log('Directive link')
},
template: 'Directive template'
};
});
});
它失敗了,奇怪的。我的所有其他模塊的寫作方式與第二個示例相同,並且工作正常。
任何指導非常讚賞。
感謝,
戴夫
這段代碼是永遠實際上被調用。你期望發生什麼?你的意思是IIFE(http://en.wikipedia.org/wiki/Immediately-invoked_function_expression)? –
只需調用函數:(function(){...})(); – pixelbits
發佈更新爲IIFE。謝謝:-) – iamdash