0
我試圖在調用指令後插入到DOM中的標籤上插入ng。在將標籤附加到DOM後,我使用$ compile($(this)($ scope))。但它不起作用。在角度js中首次編譯後插入新的ng-click
app.directive('treeDirectiveSysAdminGuide', function ($rootScope, $compile) {
return {
restricts: 'A',
replace: false,
scope: {
options: '='
}
link: function (scope, element, attrs) {
var deleteNode = null;
scope.new_node = 'new Node';
scope.reload_node = function() {
$(element).each(function() {
var id = $(this).closest("li").attr("id");
if (treeDeleted[id] == 1)
$(this).addClass("deleted");
$(this).append("<a><i id = '" + id + "' class='fa fa-info' **ng-click='nodeInfo(" + id + ")'**></i></a>");
if (!$(this).find('#' + id).hasClass('compiled')) {
$compile($(this).find('#' + id))(scope);
$(this).find('#' + id).addClass('compiled');
}
$(this).before(
$("<a class='jstree-anchor'><i class='fa fa-circle'></i></a>")
.on('click', function() {
scope.options.activate_node && scope.options.activate_node(id, true);
}));
});
});
您可以添加您的指令代碼..也解釋更多你想達到什麼? –
您不應該首先將標記插入到DOM中。嘗試使用'ng-if'或'ng-hide'來隱藏元素,然後點擊 – RJo
,這應該是這樣的:$ compile($(this))($ scope); –