[英]AngularJs: nested directives in separate js files
HTML頁面包含指令“ A”,其javascript文件包含在HEAD中。
我正在嘗試在指令“ A”內使用指令“ B”,但無法弄清楚如何從指令“ A”將JavaScript文件引用到指令“ B”
聲明頁面中的所有your files
(此處為html)。 -應用-控制器-指令-等等...
然后,角度將了解您是否將B注入A。
只有在html中顯式使用的模塊(ex
ng-controller="myctrl"
)才會在該頁面上按角度loaded
。 即使聲明(通過<script tag
)10個控制器的10個文件(js) 。 唯一加載的將是myctrl
。
例如:
我在1個文件中得到一個應用程序,然后從另一個文件中注入了1個控制器:
//myApp.js
var ngwfApp = angular.module('myApp', [ 'controller1_module',
function () {
//verbose init is ok
console.log('--> INIT : Hello application : \'\'myApp\'\' ');
}]);
//ctrl1.js
var ctrl1 = angular.module('controller1_module', []);
ctrl1.controller('myController1NameOnHtml', ['$scope', function ($scope) {
//verbose
console.log('--> INIT : Hello controller \'\'myController1NameOnHtml\'\' ');
}]);
//and so on for all files you need
在我的html中:
<!-- angular app -->
<script type="text/javascript" src="/_PATH_/myApp.js"></script>
<!-- angular controller -->
<script type="text/javascript" src="/_PATH_/ctrl1.js.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.