From a45dfc38221e927349f58ccf891228de77a3a679 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 30 Oct 2015 15:06:51 -0700 Subject: [PATCH] [Representation] Don't reuse scopes Addresses nasa/openmctweb#227 --- platform/representation/src/TemplateLinker.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/representation/src/TemplateLinker.js b/platform/representation/src/TemplateLinker.js index 426bbbe318..9a5e8a67f2 100644 --- a/platform/representation/src/TemplateLinker.js +++ b/platform/representation/src/TemplateLinker.js @@ -92,10 +92,19 @@ define( var activeElement = element, activeTemplateUrl, comment = this.$compile('')(scope), + activeScope, self = this; + function destroyScope() { + if (activeScope) { + activeScope.$destroy(); + activeScope = undefined; + } + } + function removeElement() { if (activeElement !== comment) { + destroyScope(); activeElement.replaceWith(comment); activeElement = comment; } @@ -110,8 +119,10 @@ define( } function populateElement(template) { + destroyScope(); + activeScope = scope.$new(false); element.empty(); - element.append(self.$compile(template)(scope)); + element.append(self.$compile(template)(activeScope)); } function badTemplate(templateUrl) {