88 EventEmitter ,
99 Inject ,
1010 Injectable ,
11+ Injector ,
1112 NgZone ,
1213 OnDestroy ,
1314 Type ,
@@ -16,6 +17,7 @@ import {
1617import { fromEvent , Subject , Subscription } from 'rxjs' ;
1718import { filter , takeUntil } from 'rxjs/operators' ;
1819
20+ import { fadeIn , fadeOut , IAnimationParams , scaleInHorLeft , scaleInHorRight , scaleInVerBottom , scaleInVerTop , scaleOutHorLeft , scaleOutHorRight , scaleOutVerBottom , scaleOutVerTop , slideInBottom , slideInTop , slideOutBottom , slideOutTop } from 'igniteui-angular/animations' ;
1921import { PlatformUtil } from '../../core/utils' ;
2022import { IgxOverlayOutletDirective } from '../../directives/toggle/toggle.directive' ;
2123import { IgxAngularAnimationService } from '../animation/angular-animation-service' ;
@@ -34,6 +36,7 @@ import {
3436 OverlayAnimationEventArgs ,
3537 OverlayCancelableEventArgs ,
3638 OverlayClosingEventArgs ,
39+ OverlayCreateSettings ,
3740 OverlayEventArgs ,
3841 OverlayInfo ,
3942 OverlaySettings ,
@@ -43,7 +46,6 @@ import {
4346 RelativePositionStrategy ,
4447 VerticalAlignment
4548} from './utilities' ;
46- import { fadeIn , fadeOut , IAnimationParams , scaleInHorLeft , scaleInHorRight , scaleInVerBottom , scaleInVerTop , scaleOutHorLeft , scaleOutHorRight , scaleOutVerBottom , scaleOutVerTop , slideInBottom , slideInTop , slideOutBottom , slideOutTop } from 'igniteui-angular/animations' ;
4749
4850/**
4951 * [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/overlay-main)
@@ -144,7 +146,7 @@ export class IgxOverlayService implements OnDestroy {
144146 @Inject ( DOCUMENT ) private document : any ,
145147 private _zone : NgZone ,
146148 protected platformUtil : PlatformUtil ,
147- @Inject ( IgxAngularAnimationService ) private animationService : AnimationService ) {
149+ @Inject ( IgxAngularAnimationService ) private animationService : AnimationService ) {
148150 this . _document = this . document ;
149151 }
150152
@@ -298,7 +300,7 @@ export class IgxOverlayService implements OnDestroy {
298300 * Generates Id. Provide this Id when call `show(id)` method
299301 *
300302 * @param component ElementRef to show in overlay
301- * @param settings Display settings for the overlay, such as positioning and scroll/close behavior.
303+ * @param settings (optional): Display settings for the overlay, such as positioning and scroll/close behavior.
302304 * @returns Id of the created overlay. Valid until `detach` is called.
303305 */
304306 public attach ( element : ElementRef , settings ?: OverlaySettings ) : string ;
@@ -308,23 +310,25 @@ export class IgxOverlayService implements OnDestroy {
308310 * Note created instance is in root scope, prefer the `viewContainerRef` overload when local injection context is needed.
309311 *
310312 * @param component Component Type to show in overlay
311- * @param settings Display settings for the overlay, such as positioning and scroll/close behavior.
313+ * @param settings (optional): Create settings for the overlay, such as positioning and scroll/close behavior.
314+ * Includes also an optional `Injector` to add to the created dynamic component's injectors.
312315 * @returns Id of the created overlay. Valid until `detach` is called.
313316 */
314- public attach ( component : Type < any > , settings ?: OverlaySettings ) : string ;
317+ public attach ( component : Type < any > , settings ?: OverlayCreateSettings ) : string ;
318+ // TODO: change third parameter to OverlayCreateSettings and allow passing of Injector and so on.
315319 /**
316320 * Generates an Id. Provide this Id when calling the `show(id)` method
317321 *
318322 * @param component Component Type to show in overlay
319323 * @param viewContainerRef Reference to the container where created component's host view will be inserted
320- * @param settings Display settings for the overlay, such as positioning and scroll/close behavior.
324+ * @param settings (optional): Display settings for the overlay, such as positioning and scroll/close behavior.
321325 */
322326 public attach ( component : Type < any > , viewContainerRef : ViewContainerRef , settings ?: OverlaySettings ) : string ;
323327 public attach (
324328 componentOrElement : ElementRef | Type < any > ,
325- viewContainerRefOrSettings ?: ViewContainerRef | OverlaySettings ,
326- moduleRefOrSettings ?: OverlaySettings ) : string {
327- const info : OverlayInfo = this . getOverlayInfo ( componentOrElement , viewContainerRefOrSettings ) ;
329+ viewContainerRefOrSettings ?: ViewContainerRef | OverlayCreateSettings ,
330+ settings ?: OverlaySettings ) : string {
331+ const info : OverlayInfo = this . getOverlayInfo ( componentOrElement , viewContainerRefOrSettings , settings ) ;
328332
329333 if ( ! info ) {
330334 console . warn ( 'Overlay was not able to attach provided component!' ) ;
@@ -333,9 +337,8 @@ export class IgxOverlayService implements OnDestroy {
333337
334338 info . id = ( this . _componentId ++ ) . toString ( ) ;
335339 info . visible = false ;
336- const settings = Object . assign ( { } , this . _defaultSettings , this . getUserOverlaySettings ( viewContainerRefOrSettings , moduleRefOrSettings ) ) ;
337340 // Emit the contentAppending event before appending the content
338- const eventArgs = { id : info . id , elementRef : info . elementRef , componentRef : info . componentRef , settings } ;
341+ const eventArgs = { id : info . id , elementRef : info . elementRef , componentRef : info . componentRef , settings : info . settings } ;
339342 this . contentAppending . emit ( eventArgs ) ;
340343 // Append the content to the overlay
341344 info . settings = eventArgs . settings ;
@@ -559,29 +562,38 @@ export class IgxOverlayService implements OnDestroy {
559562 }
560563 }
561564
562- private getUserOverlaySettings (
563- viewContainerRefOrSettings ?: ViewContainerRef | OverlaySettings ,
564- moduleRefOrSettings ?: OverlaySettings ) : OverlaySettings {
565- let result : OverlaySettings | undefined = moduleRefOrSettings ;
566- if ( viewContainerRefOrSettings && ! ( viewContainerRefOrSettings instanceof ViewContainerRef ) ) {
567- result = viewContainerRefOrSettings ;
568- }
569- return result ;
570- }
571-
565+ /**
566+ * Creates overlayInfo. Sets the info's `elementRef`, `componentRef`and `settings`. Also
567+ * initialize info's `ngZone`, `transformX` and `transformY`.
568+ * @param component ElementRef or Type. If type is provided dynamic component will be created
569+ * @param viewContainerRefOrSettings (optional): If ElementRef is provided for `component` this
570+ * parameter is OverlaySettings. Otherwise it could be ViewContainerRef or OverlayCreateSettings and will be
571+ * used when dynamic component is created.
572+ * @param settings (optional): OverlaySettings when `ViewContainerRef` is provided.
573+ * @returns OverlayInfo
574+ */
572575 private getOverlayInfo (
573576 component : ElementRef | Type < any > ,
574- viewContainerRefOrSettings ?: ViewContainerRef | OverlaySettings ) : OverlayInfo | null {
577+ viewContainerRefOrSettings ?: ViewContainerRef | OverlayCreateSettings ,
578+ settings ?: OverlaySettings ) : OverlayInfo | null {
575579 const info : OverlayInfo = { ngZone : this . _zone , transformX : 0 , transformY : 0 } ;
580+ let overlaySettings = settings ;
576581 if ( component instanceof ElementRef ) {
577582 info . elementRef = component ;
583+ overlaySettings = viewContainerRefOrSettings as OverlaySettings ;
578584 } else {
579585 let dynamicComponent : ComponentRef < any > ;
580586 if ( viewContainerRefOrSettings instanceof ViewContainerRef ) {
581- dynamicComponent = viewContainerRefOrSettings . createComponent ( component ) ;
587+ const viewContainerRef = viewContainerRefOrSettings as ViewContainerRef ;
588+ dynamicComponent = viewContainerRef . createComponent ( component ) ;
582589 } else {
583590 const environmentInjector = this . _appRef . injector ;
584- dynamicComponent = createComponent ( component , { environmentInjector } ) ;
591+ const createSettings = viewContainerRefOrSettings as OverlayCreateSettings | undefined ;
592+ let elementInjector : Injector ;
593+ if ( createSettings ) {
594+ ( { injector : elementInjector , ...overlaySettings } = createSettings ) ;
595+ }
596+ dynamicComponent = createComponent ( component , { environmentInjector, elementInjector } ) ;
585597 this . _appRef . attachView ( dynamicComponent . hostView ) ;
586598 }
587599 if ( dynamicComponent . onDestroy ) {
@@ -597,6 +609,7 @@ export class IgxOverlayService implements OnDestroy {
597609 info . elementRef = { nativeElement : element } ;
598610 info . componentRef = dynamicComponent ;
599611 }
612+ info . settings = Object . assign ( { } , this . _defaultSettings , overlaySettings ) ;
600613 return info ;
601614 }
602615
0 commit comments