Skip to content

Commit 008c1e2

Browse files
authored
Merge pull request #132 from SoCreate/fix/component-not-destroyed-when-search-text-cleared
fix bug where sandboxed component is not removed when the search bar text is cleared
2 parents 123eb93 + 0574d94 commit 008c1e2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/angular-playground/core/src/scenario/scenario.component.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ export class ScenarioComponent implements OnInit, OnChanges, OnDestroy {
4949

5050
ngOnDestroy() {
5151
this.onDestroy.next();
52+
53+
// this cleans up the DOM when a sandboxed component is loaded and the search bar is then cleared
54+
if (this.activeApps.length > 0) {
55+
// destroy sandboxed app (doesn't remove it from the DOM though)
56+
const app = this.activeApps.pop();
57+
app.destroy();
58+
59+
// remove the sandboxed component's element from the dom
60+
const hostElement = document.querySelector('playground-host');
61+
if (hostElement && hostElement.children) {
62+
hostElement.children[0].remove();
63+
}
64+
}
5265
}
5366

5467
/**

0 commit comments

Comments
 (0)