1
- import { Component , Injector , PLATFORM_ID , inject } from '@angular/core' ;
1
+ import {
2
+ Component ,
3
+ Injector ,
4
+ PLATFORM_ID ,
5
+ inject ,
6
+ OnDestroy ,
7
+ } from '@angular/core' ;
2
8
import { RouterOutlet } from '@angular/router' ;
3
9
import { isPlatformBrowser } from '@angular/common' ;
4
10
import { MenuComponent } from './components/menu.component' ;
@@ -11,7 +17,6 @@ import { FooterComponent } from './components/footer.component';
11
17
12
18
@Component ( {
13
19
selector : 'ngrx-root' ,
14
- standalone : true ,
15
20
imports : [
16
21
RouterOutlet ,
17
22
MenuComponent ,
@@ -47,39 +52,56 @@ import { FooterComponent } from './components/footer.component';
47
52
` ,
48
53
] ,
49
54
} )
50
- export class AppComponent {
51
- injector = inject ( Injector ) ;
52
- platformId = inject ( PLATFORM_ID ) ;
55
+ export class AppComponent implements OnDestroy {
56
+ private isAlive = true ;
57
+ private injector = inject ( Injector ) ;
58
+ private platformId = inject ( PLATFORM_ID ) ;
53
59
54
60
constructor ( ) {
55
61
if ( isPlatformBrowser ( this . platformId ) ) {
56
62
this . installCustomElements ( ) ;
57
63
}
58
64
}
59
65
66
+ ngOnDestroy ( ) : void {
67
+ this . isAlive = false ;
68
+ }
69
+
60
70
async installCustomElements ( ) {
71
+ if ( ! this . isAlive ) return ;
72
+
61
73
const { createCustomElement } = await import ( '@angular/elements' ) ;
62
74
75
+ if ( ! this . isAlive ) return ;
76
+
63
77
const symbolLinkElement = createCustomElement ( MarkdownSymbolLinkComponent , {
64
78
injector : this . injector ,
65
79
} ) ;
66
80
customElements . define ( 'ngrx-docs-symbol-link' , symbolLinkElement ) ;
67
81
82
+ if ( ! this . isAlive ) return ;
83
+
68
84
const alertElement = createCustomElement ( AlertComponent , {
69
85
injector : this . injector ,
70
86
} ) ;
71
87
customElements . define ( 'ngrx-docs-alert' , alertElement ) ;
72
88
89
+ if ( ! this . isAlive ) return ;
90
+
73
91
const codeExampleElement = createCustomElement ( CodeExampleComponent , {
74
92
injector : this . injector ,
75
93
} ) ;
76
94
customElements . define ( 'ngrx-code-example' , codeExampleElement ) ;
77
95
96
+ if ( ! this . isAlive ) return ;
97
+
78
98
const codeTabsElement = createCustomElement ( CodeTabsComponent , {
79
99
injector : this . injector ,
80
100
} ) ;
81
101
customElements . define ( 'ngrx-code-tabs' , codeTabsElement ) ;
82
102
103
+ if ( ! this . isAlive ) return ;
104
+
83
105
const stackblitzElement = createCustomElement ( StackblitzComponent , {
84
106
injector : this . injector ,
85
107
} ) ;
0 commit comments