【发布时间】:2016-08-22 15:30:37
【问题描述】:
我想在内部作用域被销毁后重新编译它。
我正在使用重新编译功能来帮助,这是“嵌入”为真。 每当我想破坏内部作用域时,它也会破坏父(外部)作用域。
如何在保持重新编译功能不变的同时避免删除父作用域?
function compile() {
transclude(scope, function(clone, clonedScope) {
previousElements = clone;
$el.append(clone);
$timeout(function () {
scope.callBack();
alert("Df");
}, 0);
});
}
$scope.callBack = function(){
var elem = document.getElementById('test');
//This code kill the test div, but also the parent scope
//Can i only kill the test div scope?
angular.element(elem).scope().$destroy();
alert("dd");
}
这里是 plunker: http://plnkr.co/edit/MePu8BipkkdHV0IEatbo
【问题讨论】:
-
你真的不应该破坏一个范围,除非你是创造它的人。
-
我很确定这不是实现您尝试的方法。你的目标是什么?
标签: angularjs angular-directive