4
4
Inject ,
5
5
ModuleWithProviders ,
6
6
ANALYZE_FOR_ENTRY_COMPONENTS ,
7
- Type
7
+ Type ,
8
+ SkipSelf
8
9
} from '@angular/core' ;
9
10
import { CommonModule } from '@angular/common' ;
10
11
@@ -16,9 +17,19 @@ import {
16
17
} from './lazy-elements-loader.service' ;
17
18
import {
18
19
LAZY_ELEMENT_ROOT_OPTIONS ,
19
- LAZY_ELEMENT_CONFIGS
20
+ LAZY_ELEMENT_CONFIGS ,
21
+ LAZY_ELEMENT_ROOT_GUARD
20
22
} from './lazy-elements.tokens' ;
21
23
24
+ export function createLazyElementRootGuard ( options : LazyElementModuleOptions ) {
25
+ if ( options ) {
26
+ throw new TypeError (
27
+ `LazyElementsModule.forRoot() called twice. Feature modules should use ThemeModule.forFeature() instead.`
28
+ ) ;
29
+ }
30
+ return 'guarded' ;
31
+ }
32
+
22
33
@NgModule ( {
23
34
declarations : [ LazyElementDirective , LazyElementDynamicDirective ] ,
24
35
imports : [ CommonModule ] ,
@@ -44,6 +55,11 @@ export class LazyElementsModule {
44
55
provide : ANALYZE_FOR_ENTRY_COMPONENTS ,
45
56
useValue : options ,
46
57
multi : true
58
+ } ,
59
+ {
60
+ provide : LAZY_ELEMENT_ROOT_GUARD ,
61
+ useFactory : createLazyElementRootGuard ,
62
+ deps : [ [ LAZY_ELEMENT_CONFIGS , new Optional ( ) , new SkipSelf ( ) ] ]
47
63
}
48
64
]
49
65
} ;
@@ -72,7 +88,10 @@ export class LazyElementsModule {
72
88
lazyElementsLoaderService : LazyElementsLoaderService ,
73
89
@Optional ( )
74
90
@Inject ( LAZY_ELEMENT_CONFIGS )
75
- elementConfigsMultiProvider : ElementConfig [ ] [ ]
91
+ elementConfigsMultiProvider : ElementConfig [ ] [ ] ,
92
+ @Optional ( )
93
+ @Inject ( LAZY_ELEMENT_ROOT_GUARD )
94
+ guard : any
76
95
) {
77
96
if ( elementConfigsMultiProvider && elementConfigsMultiProvider . length ) {
78
97
const lastAddedConfigs =
0 commit comments