From dea2ab97ad57958470732ff9db640b41307eb8e2 Mon Sep 17 00:00:00 2001 From: Cody Mikol Date: Tue, 2 Oct 2018 12:17:11 -0400 Subject: [PATCH] fix(interimElement): don't track elements that fail compilation prevent interimElements from being tracked as showingInterimElements when they fail to be compiled Fixes: #11460 --- src/components/dialog/dialog.spec.js | 38 +++++++++++++++++++ .../services/interimElement/interimElement.js | 8 +++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/components/dialog/dialog.spec.js b/src/components/dialog/dialog.spec.js index 41ef81c3a0..d38b90baf8 100644 --- a/src/components/dialog/dialog.spec.js +++ b/src/components/dialog/dialog.spec.js @@ -1439,6 +1439,44 @@ describe('$mdDialog', function() { expect(parent[0].querySelectorAll('md-dialog.two').length).toBe(0); })); + it('should be able to close a dialog when a child dialog fails to compile', inject(function ($mdDialog, $q) { + + var root = angular.element('
'); + + var parent = angular.element(''); + + var child = angular.element(''); + + $mdDialog.show({ + template: parent, + multiple: true, + parent: root, + }); + runAnimation(); + + expect(root[0].querySelectorAll('md-dialog').length).toBe(1); + + $mdDialog.show({ + template: child, + multiple: true, + parent: parent, + resolve: { + fail: function () { + return $q.reject(); + } + }, + }); + runAnimation(); + + expect(root[0].querySelectorAll('md-dialog').length).toBe(1); + + $mdDialog.hide(); + runAnimation(); + + expect(root[0].querySelectorAll('md-dialog').length).toBe(0); + + })); + describe('contentElement', function() { var $mdDialog, $rootScope, $compile, $timeout; diff --git a/src/core/services/interimElement/interimElement.js b/src/core/services/interimElement/interimElement.js index 617add1451..ac4e6730bf 100644 --- a/src/core/services/interimElement/interimElement.js +++ b/src/core/services/interimElement/interimElement.js @@ -310,10 +310,14 @@ function InterimElementProvider() { return interimElement .show() - .catch(function(reason) { return reason; }) + .then(function () { + showingInterims.push(interimElement); + }) + .catch(function (reason) { + return reason; + }) .finally(function() { showPromises.splice(showPromises.indexOf(showAction), 1); - showingInterims.push(interimElement); }); });