File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ export * from './lib/di/before-render';
3
3
export * from './lib/di/catalogue' ;
4
4
export * from './lib/di/destroy' ;
5
5
export * from './lib/di/ref' ;
6
+ export * from './lib/di/run-in-context' ;
6
7
export * from './lib/directives/args' ;
7
8
export * from './lib/directives/repeat' ;
8
9
export * from './lib/loader' ;
Original file line number Diff line number Diff line change
1
+ import { EnvironmentInjector , inject , Injector } from '@angular/core' ;
2
+
3
+ export function createRunInContext ( ) {
4
+ const nodeInjector = inject ( Injector ) ;
5
+ const envInjector = inject ( EnvironmentInjector ) ;
6
+
7
+ const originalGet = envInjector . get ;
8
+
9
+ return < TReturn > ( cb : ( ) => TReturn ) : TReturn => {
10
+ envInjector . get = ( ...args : Parameters < EnvironmentInjector [ 'get' ] > ) => {
11
+ try {
12
+ const fromNodeInjector = nodeInjector . get ( ...( args as Parameters < Injector [ 'get' ] > ) ) ;
13
+ if ( fromNodeInjector ) return fromNodeInjector ;
14
+ return originalGet ( ...args ) ;
15
+ } catch ( e ) {
16
+ return originalGet ( ...args ) ;
17
+ }
18
+ } ;
19
+
20
+ return envInjector . runInContext ( cb ) ;
21
+ } ;
22
+ }
You can’t perform that action at this time.
0 commit comments