ユーザーが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
を使用して、この動的に追加ディレクティブをテストしたいです。 startExtension
イベントの
$scope.$on('startExtension', function (event, id) {
var el = $compile("<" + id + ">" + "</" + id + ">")($scope);
$element.append(el);
});
id
引数は、私は動的ディレクティブを定義するために使用extension._id
と全く同じです。
$コンパイル後、ディレクティブは置き換えられません。 DOMについては、以下のようになります
<testid class="ng-scope"></testid>
ありがとうございました。