![](/img/trans.png)
[英]Is there a way to detect when a DOM node is about to be removed from the DOM?
[英]Detect if directive was removed from DOM
我有一個AngularJS指令,如果該指令的元素已從DOM中刪除(從AngularJS調用內部或通過任何其他方法,如jQuery),則需要執行某些操作。
那可能嗎?
當您的指令從DOM中刪除時,會觸發$destroy
事件。 看到這里https://docs.angularjs.org/api/ng/type/ $ rootScope.Scope#$ destroy
在這個問題中( 提供范圍的$ destroy事件的示例嗎? ),我找到了以下示例:
ctrl.directive('handleDestroy', function() {
return function(scope, tElement, attributes) {
scope.$on('$destroy', function() {
alert("In destroy of:" + scope.todo.text);
});
};
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.