From 48955d692b2e343952bca04705368ca0b23b7aaf Mon Sep 17 00:00:00 2001 From: dmitry-dedukhin Date: Fri, 13 Dec 2013 16:05:24 +0300 Subject: [PATCH] fix(datepicker): remove datepicker's popup on scope destroy --- src/datepicker/datepicker.js | 1 + src/datepicker/test/datepicker.spec.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index bc1aa7cb33..f960ab1744 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -281,6 +281,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? originalScope.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar; originalScope.$on('$destroy', function() { + $popup.remove(); scope.$destroy(); }); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 499b3dfdf5..f22aa99fe5 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1298,6 +1298,19 @@ describe('datepicker directive', function () { expect($body.children().length).toEqual(bodyLength + 1); expect(elm.children().length).toEqual(1); }); + it('should be removed on scope destroy', function() { + var $body = $document.find('body'), + bodyLength = $body.children().length, + isolatedScope = $rootScope.$new(), + elm = angular.element( + '' + ); + $compile(elm)(isolatedScope); + isolatedScope.$digest(); + expect($body.children().length).toEqual(bodyLength + 1); + isolatedScope.$destroy(); + expect($body.children().length).toEqual(bodyLength); + }); }); describe('with setting datepickerConfig.showWeeks to false', function() {