[英]Directives Talking to Controllers - Why isn't my module working? (Angular JS)
[英]Why is my directives module not being included in my Angular app module?
剛學習Angular時,我遇到了一些模塊解析問題。 在js/directives/directives.js
我將以下指令限制為directives
模塊:
angular.module("directives").directive("selectList", function() {
return {
restrict: 'E',
link: function() {
// do stuff
}
}
});
在我的網頁上:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<script>
angular.module("editUserApp", ["directives"])
.controller("editUserController", ['$http', '$scope', function($http, $scope) {
// do stuff here
}]
);
</script>
我收到的錯誤如下:
Error: [$injector:modulerr] Failed to instantiate module editUserApp due to:
[$injector:modulerr] Failed to instantiate module directives due to:
[$injector:nomod] Module 'directives' 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.
現在,很明顯, editUserApp
本身不知道directives
在哪里,那么我如何告訴它獲取指令editUserApp
文件? 我是否必須將其包含在腳本標簽中(似乎不是很可擴展)?
我需要某種方式將指令導入我的角度應用程序。 我怎樣才能做到這一點?
你需要
angular.module("directives" ,[])
在你的第一個街區
angular.module("directives")
嘗試找到稱為指令的現有模塊
如果您正在尋找一種根據需要導入這些文件的方法,則可能需要查看http://requirejs.org/或http://browserify.org/或類似的工具。
您需要將js / directives / directives.js文件包含到html中,並刪除App模塊上的指令依賴項。
您的代碼應為:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<script>
angular.module("editUserApp", [])
.controller("editUserController", ['$http','directives', '$scope', function($http, $scope,directives) {
// do stuff here
}]
);
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.