From 0574d94349344268f0d9db5a5c859c0a77cb14c3 Mon Sep 17 00:00:00 2001 From: Timothy Stoddard Date: Fri, 17 Aug 2018 14:07:27 -0700 Subject: [PATCH] fix playground bug where sandboxed component is not removed when the search bar text is cleared --- .../core/src/scenario/scenario.component.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/angular-playground/core/src/scenario/scenario.component.ts b/packages/angular-playground/core/src/scenario/scenario.component.ts index 66b2532b..88364b2f 100644 --- a/packages/angular-playground/core/src/scenario/scenario.component.ts +++ b/packages/angular-playground/core/src/scenario/scenario.component.ts @@ -55,6 +55,19 @@ export class ScenarioComponent implements OnInit, OnChanges, OnDestroy { ngOnDestroy() { this.onDestroy.next(); + + // this cleans up the DOM when a sandboxed component is loaded and the search bar is then cleared + if (this.activeApps.length > 0) { + // destroy sandboxed app (doesn't remove it from the DOM though) + const app = this.activeApps.pop(); + app.destroy(); + + // remove the sandboxed component's element from the dom + const hostElement = document.querySelector('playground-host'); + if (hostElement && hostElement.children) { + hostElement.children[0].remove(); + } + } } /**