我正在尝试做一个扩展管理器,用户可以在其中运行和测试他们的Angularjs指令。动态定义的指令没有被编译
用户创建一个extension
对象,并将其传递给我注册指令的函数。
angular.module('CloudBoxes').directive(extension._id,
function() {
return {
template: extension.html,
restrict: 'E',
replace: true,
link: extension.js.controller,
scope: extension.js.scope
};
}
);
测试对象extension
{
_id: "testid",
js: {
title: "System.Dir",
fa: "fa-folder",
include: ["$http"],
controller: function (scope, element, attrs) {
alert("I am ready");
},
scope: {
args: "=",
}
},
html: "<div></div>"
};
而且我想在我的控制器的一个测试用$compile
这个动态添加指令。
$scope.$on('startExtension', function (event, id) {
var el = $compile("<" + id + ">" + "</" + id + ">")($scope);
$element.append(el);
});
id
上startExtension
事件参数是我将用于动态定义指令中extension._id
完全相同。
但是在$ compile之后,指令不会被替换。在DOM上,它就像下面那样
<testid class="ng-scope"></testid>
谢谢你的帮助。