From 540c5f8fc3375cc3c3bc83f7a1e6fb835971f04e Mon Sep 17 00:00:00 2001 From: Marcin Wosinek Date: Mon, 5 Nov 2018 12:06:18 +0100 Subject: [PATCH] Skip linking if elemented already removed in the meantime --- clickoutside.directive.js | 9 +++++++++ package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clickoutside.directive.js b/clickoutside.directive.js index 829b465..65aa80d 100644 --- a/clickoutside.directive.js +++ b/clickoutside.directive.js @@ -22,9 +22,18 @@ return { restrict: 'A', link: function($scope, elem, attr) { + let isDestoyed = false; + + $scope.$on('$destroy', function() { + isDestoyed = true; + }); // postpone linking to next digest to allow for unique id generation $timeout(function() { + if (isDestoyed) { + return; + } + var classList = (attr.outsideIfNot !== undefined) ? attr.outsideIfNot.split(/[ ,]+/) : [], fn; diff --git a/package.json b/package.json index 19190fc..7542002 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "iamadamjowett/angular-click-outside", + "name": "angular-click-outside", "version": "2.11.0", "main": "clickoutside.directive.js", "author": {