Wottensprels
Wottensprels

Reputation: 3327

AngularJs - Should I destroy a directive instance manually?

Consider an application that utilizes ngRepeat to show a list of directive instances.

When an element is removed from the list, should I manually destroy the directive instance or is it safe enough to call splice() on the array that holds the element?

The developer guide is not very helpful here.

Upvotes: 2

Views: 514

Answers (1)

Matt Way
Matt Way

Reputation: 33179

If you are in doubt and want to check whether the directive is actually getting destroyed, you could put a watch on $destroy in your directive. For example:

// inside your link function
scope.$on('$destroy', function() {
    console.log("destroyed");
});

Upvotes: 2

Related Questions