Answer the question
In order to leave comments, you need to log in
Angular: Will a directive be garbage collected after the object the directive is bound to disappears?
The directive is bound to the element.
app.directive('myDirective',function(){
return{
restrict:'ACE',
link: function(scope, element){
element.bind('click',function(){
doSomething();
});
}
}
});
<input type="text" my-directive value="">
Answer the question
In order to leave comments, you need to log in
The browser (webview) will take care of this, because if there is no directive, then there is no element to which it is attached. Therefore, the browser itself will remove all event handlers along with the element being removed.
If the directive hangs handlers on something higher ($window, $document for example) then yes, then you need to do unbind on the $destroy event of $scope.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question