Found this code one of the directives in a project I'm working on:
element.on('$destroy', function () {
scope.$destroy();
});
Is this code needed? Or can I remove it? Isn't scope destroyed when directive is destroyed?
You don't have to write this code.
As per the docs, the $destroy event is triggered in two cases.
As a side note, you can still use the scope of the element in the element.on('$destroy') event before the scope will be destroyed:
element.on('$destroy', function() {
console.log('RIP', scope);
});
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