0
我在我的Angular應用程序中使用RequireJS。我想require
我的pill
它實際使用。需要指令模板
pill.js
define([], function() {
angular.module('app').directive('pill', function() {
return function(a,b,c) {
b.html("A pill");
};
});
});
incl.html
<div load-script="require(['pill']);"></div>
<div pill>test</div>
main.html中
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>
<script src="http://requirejs.org/docs/release/2.1.10/comments/require.js"></script>
</head>
<body>
<script>
var app = angular.module("app", [])
app.directive('loadScript', function() {
return {
link: function(scope, element, attrs) {
(new Function(attrs.loadScript))();
}
};
}
);
</script>
<div ng-include="'incl.html'"></div>
</body>
</html>
此簡短的例子應該DECL是一個pill
指令,它只是將test
中的文本轉換爲incl.html
文件中的A pill
。但是,它不起作用。我猜這是因爲pill
指令是在編譯incl.html
後註冊的。
我想避免宣佈指令somwhere例如在main.html
內,因爲它沒有在那裏使用。這個要求是否可以用優雅的方式實現?