File tree Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Original file line number Diff line number Diff line change 1
- import { InjectionToken , Provider } from '@angular/core' ;
1
+ import { Inject , Injectable , InjectionToken , Provider } from '@angular/core' ;
2
2
3
3
/**
4
4
* Extra configuration for {@link DynamicMenuModule}
@@ -19,19 +19,30 @@ export interface DynamicMenuExtras {
19
19
* DI token that hold extra configuration
20
20
* @internal
21
21
*/
22
- export class DynamicMenuExtrasToken implements DynamicMenuExtras {
23
- constructor ( public listenForConfigChanges = false ) { }
22
+ export const DynamicMenuExtrasToken = new InjectionToken < DynamicMenuExtras > (
23
+ 'DynamicMenuExtrasToken' ,
24
+ ) ;
25
+
26
+ /**
27
+ * @internal
28
+ */
29
+ @Injectable ( { providedIn : 'root' } )
30
+ export class DynamicMenuExtrasService implements DynamicMenuExtras {
31
+ listenForConfigChanges = this . extras . listenForConfigChanges ;
32
+
33
+ constructor (
34
+ @Inject ( DynamicMenuExtrasToken )
35
+ private extras : DynamicMenuExtras = { listenForConfigChanges : false } ,
36
+ ) { }
24
37
}
25
38
26
39
/**
27
40
* Helper function to provide {@link DYNAMIC_MENU_EXTRAS_TOKEN}
28
41
* @internal
29
42
*/
30
- export function provideDynamicMenuExtras (
31
- extras : DynamicMenuExtras = { } ,
32
- ) : Provider {
43
+ export function provideDynamicMenuExtras ( extras ?: DynamicMenuExtras ) : Provider {
33
44
return {
34
45
provide : DynamicMenuExtrasToken ,
35
- useValue : new DynamicMenuExtrasToken ( extras . listenForConfigChanges ) ,
46
+ useValue : extras ,
36
47
} ;
37
48
}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import {
19
19
takeUntil ,
20
20
} from 'rxjs/operators' ;
21
21
22
- import { DynamicMenuExtrasToken } from './dynamic-menu-extras' ;
22
+ import { DynamicMenuExtrasService } from './dynamic-menu-extras' ;
23
23
import { DYNAMIC_MENU_ROUTES_TOKEN } from './dynamic-menu-routes' ;
24
24
import { SUB_MENU_MAP_TOKEN , SubMenuMap } from './sub-menu-map-provider' ;
25
25
import {
@@ -58,7 +58,7 @@ export class DynamicMenuService implements OnDestroy {
58
58
refCount ( ) ,
59
59
) ;
60
60
61
- private configChanged$ = this . dynamicMenuExtrasToken . listenForConfigChanges
61
+ private configChanged$ = this . dynamicMenuExtrasService . listenForConfigChanges
62
62
? this . router . events . pipe ( filter ( e => e instanceof RouteConfigLoadEnd ) )
63
63
: EMPTY ;
64
64
@@ -103,7 +103,7 @@ export class DynamicMenuService implements OnDestroy {
103
103
constructor (
104
104
private injector : Injector ,
105
105
private router : Router ,
106
- private dynamicMenuExtrasToken : DynamicMenuExtrasToken ,
106
+ private dynamicMenuExtrasService : DynamicMenuExtrasService ,
107
107
) {
108
108
this . dynamicMenu$ . pipe ( takeUntil ( this . destroyed$ ) ) . subscribe ( ) ;
109
109
}
You can’t perform that action at this time.
0 commit comments