So, I have these widgets:
<widget ng-repeat="widget in widgets"></widget>
As you can tell, they are created and removed by the ng-repeat
.
So when someone does remove a widget, is there any where in the directive I can catch the event happening OR equivalent?
.directive('widget', function widget() {
var directive = {
restrict: 'E',
compile: compile
};
return directive;
function compile() {
return {
pre: preLink,
post: postLink
};
}
function preLink(scope, element) {
}
function postLink(scope, element) {
}
});
You can listen to the $destroy event which will be fired immediately prior to scope destruction.
The $destroy() is usually used by directives such as ngRepeat for managing the unrolling of the loop.
scope.$on('$destroy', function () {
console.log('captured $destroy event');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With