11import { coerceArray , concatArray , FunctionProp , keyBy } from 'ngx-tethys/util' ;
2- import { Subject } from 'rxjs' ;
3-
2+ import { of , Subject } from 'rxjs' ;
43import { ComponentType , Overlay , OverlayConfig , OverlayRef , ScrollStrategy } from '@angular/cdk/overlay' ;
54import { ComponentPortal , TemplatePortal } from '@angular/cdk/portal' ;
6- import { Injector , reflectComponentType , TemplateRef } from '@angular/core' ;
7-
5+ import { Injector , reflectComponentType , StaticProvider , TemplateRef } from '@angular/core' ;
86import { SafeAny } from 'ngx-tethys/types' ;
97import { ThyAbstractOverlayContainer } from './abstract-overlay-container' ;
108import { ThyAbstractOverlayRef } from './abstract-overlay-ref' ;
119import { ThyAbstractOverlayConfig , ThyAbstractOverlayOptions } from './abstract-overlay.config' ;
10+ import { Directionality } from '@angular/cdk/bidi' ;
1211
1312export type ComponentTypeOrTemplateRef < T > = ComponentType < T > | TemplateRef < T > ;
1413
@@ -25,7 +24,7 @@ export abstract class ThyAbstractOverlayService<TConfig extends ThyAbstractOverl
2524 protected injector : Injector ,
2625 protected defaultConfig : TConfig ,
2726 public scrollStrategy ?: FunctionProp < ScrollStrategy >
28- ) { }
27+ ) { }
2928
3029 /** Build cdk overlay config by config */
3130 protected abstract buildOverlayConfig ( config : TConfig ) : OverlayConfig ;
@@ -40,12 +39,39 @@ export abstract class ThyAbstractOverlayService<TConfig extends ThyAbstractOverl
4039 config : TConfig
4140 ) : ThyAbstractOverlayRef < T , TContainer , TResult > ;
4241
42+
43+ /** Create injector providers for component content */
44+ protected abstract createInjectorProviders < T > (
45+ overlayRef : ThyAbstractOverlayRef < T , TContainer > ,
46+ containerInstance : TContainer
47+ ) : StaticProvider [ ] ;
48+
4349 /** Create injector for component content */
44- protected abstract createInjector < T > (
50+ protected createInjector < T > (
4551 config : TConfig ,
4652 overlayRef : ThyAbstractOverlayRef < T , TContainer > ,
4753 containerInstance : TContainer
48- ) : Injector ;
54+ ) : Injector {
55+ const userInjector = config && config . viewContainerRef && config . viewContainerRef . injector ;
56+
57+ const injectionProviders = this . createInjectorProviders ( overlayRef , containerInstance ) ;
58+
59+ if ( config ?. providers ?. length ) {
60+ injectionProviders . unshift ( ...config . providers )
61+ }
62+
63+ if ( config . direction && ( ! userInjector || ! userInjector . get < Directionality | null > ( Directionality , null ) ) ) {
64+ injectionProviders . push ( {
65+ provide : Directionality ,
66+ useValue : {
67+ value : config . direction ,
68+ change : of ( )
69+ }
70+ } ) ;
71+ }
72+
73+ return Injector . create ( { parent : userInjector || this . injector , providers : injectionProviders } ) ;
74+ } ;
4975
5076 /** Attach component or template ref to overlay container */
5177 protected attachOverlayContent < T , TResult > (
0 commit comments