1
- import { Injectable , OnInit } from '@angular/core' ;
1
+ import { EnvironmentInjector , Injectable , runInInjectionContext } from '@angular/core' ;
2
2
import { ConfigService } from "./config.service" ;
3
3
import { BackendService } from "./backend.service" ;
4
4
@@ -10,26 +10,26 @@ export class NavigationService {
10
10
constructor ( private backend : BackendService , private config : ConfigService ) {
11
11
}
12
12
13
- async getMainNavigation ( context : OnInit ) : Promise < Array < GroupItem > > {
14
- return this . checkPermissions ( this . config . getNavigation ( ) , context ) ;
13
+ async getMainNavigation ( injector : EnvironmentInjector ) : Promise < Array < GroupItem > > {
14
+ return this . checkPermissions ( this . config . getNavigation ( ) , injector ) ;
15
15
}
16
16
17
- async getUserNavigation ( context : OnInit ) : Promise < Array < Item > > {
18
- return this . checkPermissionItems ( this . config . getUserNavigation ( ) , context ) ;
17
+ async getUserNavigation ( injector : EnvironmentInjector ) : Promise < Array < Item > > {
18
+ return this . checkPermissionItems ( this . config . getUserNavigation ( ) , injector ) ;
19
19
}
20
20
21
- async getAnonymousNavigation ( context : OnInit ) : Promise < Array < Item > > {
22
- return this . checkPermissionItems ( this . config . getAnonymousNavigation ( ) , context ) ;
21
+ async getAnonymousNavigation ( injector : EnvironmentInjector ) : Promise < Array < Item > > {
22
+ return this . checkPermissionItems ( this . config . getAnonymousNavigation ( ) , injector ) ;
23
23
}
24
24
25
- async getAccountNavigation ( context : OnInit ) : Promise < Array < Item > > {
26
- return this . checkPermissionItems ( this . config . getAccountNavigation ( ) , context ) ;
25
+ async getAccountNavigation ( injector : EnvironmentInjector ) : Promise < Array < Item > > {
26
+ return this . checkPermissionItems ( this . config . getAccountNavigation ( ) , injector ) ;
27
27
}
28
28
29
- private async checkPermissions ( navigation : Array < GroupItem > , context : OnInit ) : Promise < Array < GroupItem > > {
29
+ private async checkPermissions ( navigation : Array < GroupItem > , injector : EnvironmentInjector ) : Promise < Array < GroupItem > > {
30
30
let result = [ ] ;
31
31
for ( let i = 0 ; i < navigation . length ; i ++ ) {
32
- const children = await this . checkPermissionItems ( navigation [ i ] . children , context ) ;
32
+ const children = await this . checkPermissionItems ( navigation [ i ] . children , injector ) ;
33
33
if ( children . length > 0 ) {
34
34
let menu = navigation [ i ] ;
35
35
menu . children = children ;
@@ -40,9 +40,9 @@ export class NavigationService {
40
40
return result ;
41
41
}
42
42
43
- private async checkPermissionItems ( items : Items , context : OnInit ) : Promise < Array < Item > > {
43
+ private async checkPermissionItems ( items : Items , injector : EnvironmentInjector ) : Promise < Array < Item > > {
44
44
if ( items instanceof Function ) {
45
- items = await items . apply ( context ) ;
45
+ items = await runInInjectionContext ( injector , items ) ;
46
46
}
47
47
48
48
if ( ! Array . isArray ( items ) ) {
0 commit comments