8
8
EventEmitter ,
9
9
Inject ,
10
10
Injectable ,
11
+ Injector ,
11
12
NgZone ,
12
13
OnDestroy ,
13
14
Type ,
@@ -16,6 +17,7 @@ import {
16
17
import { fromEvent , Subject , Subscription } from 'rxjs' ;
17
18
import { filter , takeUntil } from 'rxjs/operators' ;
18
19
20
+ import { fadeIn , fadeOut , IAnimationParams , scaleInHorLeft , scaleInHorRight , scaleInVerBottom , scaleInVerTop , scaleOutHorLeft , scaleOutHorRight , scaleOutVerBottom , scaleOutVerTop , slideInBottom , slideInTop , slideOutBottom , slideOutTop } from 'igniteui-angular/animations' ;
19
21
import { PlatformUtil } from '../../core/utils' ;
20
22
import { IgxOverlayOutletDirective } from '../../directives/toggle/toggle.directive' ;
21
23
import { IgxAngularAnimationService } from '../animation/angular-animation-service' ;
@@ -34,6 +36,7 @@ import {
34
36
OverlayAnimationEventArgs ,
35
37
OverlayCancelableEventArgs ,
36
38
OverlayClosingEventArgs ,
39
+ OverlayCreateSettings ,
37
40
OverlayEventArgs ,
38
41
OverlayInfo ,
39
42
OverlaySettings ,
@@ -43,7 +46,6 @@ import {
43
46
RelativePositionStrategy ,
44
47
VerticalAlignment
45
48
} from './utilities' ;
46
- import { fadeIn , fadeOut , IAnimationParams , scaleInHorLeft , scaleInHorRight , scaleInVerBottom , scaleInVerTop , scaleOutHorLeft , scaleOutHorRight , scaleOutVerBottom , scaleOutVerTop , slideInBottom , slideInTop , slideOutBottom , slideOutTop } from 'igniteui-angular/animations' ;
47
49
48
50
/**
49
51
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/overlay-main)
@@ -144,7 +146,7 @@ export class IgxOverlayService implements OnDestroy {
144
146
@Inject ( DOCUMENT ) private document : any ,
145
147
private _zone : NgZone ,
146
148
protected platformUtil : PlatformUtil ,
147
- @Inject ( IgxAngularAnimationService ) private animationService : AnimationService ) {
149
+ @Inject ( IgxAngularAnimationService ) private animationService : AnimationService ) {
148
150
this . _document = this . document ;
149
151
}
150
152
@@ -298,7 +300,7 @@ export class IgxOverlayService implements OnDestroy {
298
300
* Generates Id. Provide this Id when call `show(id)` method
299
301
*
300
302
* @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.
302
304
* @returns Id of the created overlay. Valid until `detach` is called.
303
305
*/
304
306
public attach ( element : ElementRef , settings ?: OverlaySettings ) : string ;
@@ -308,23 +310,25 @@ export class IgxOverlayService implements OnDestroy {
308
310
* Note created instance is in root scope, prefer the `viewContainerRef` overload when local injection context is needed.
309
311
*
310
312
* @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.
312
315
* @returns Id of the created overlay. Valid until `detach` is called.
313
316
*/
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.
315
319
/**
316
320
* Generates an Id. Provide this Id when calling the `show(id)` method
317
321
*
318
322
* @param component Component Type to show in overlay
319
323
* @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.
321
325
*/
322
326
public attach ( component : Type < any > , viewContainerRef : ViewContainerRef , settings ?: OverlaySettings ) : string ;
323
327
public attach (
324
328
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 ) ;
328
332
329
333
if ( ! info ) {
330
334
console . warn ( 'Overlay was not able to attach provided component!' ) ;
@@ -333,9 +337,8 @@ export class IgxOverlayService implements OnDestroy {
333
337
334
338
info . id = ( this . _componentId ++ ) . toString ( ) ;
335
339
info . visible = false ;
336
- const settings = Object . assign ( { } , this . _defaultSettings , this . getUserOverlaySettings ( viewContainerRefOrSettings , moduleRefOrSettings ) ) ;
337
340
// 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 } ;
339
342
this . contentAppending . emit ( eventArgs ) ;
340
343
// Append the content to the overlay
341
344
info . settings = eventArgs . settings ;
@@ -559,29 +562,38 @@ export class IgxOverlayService implements OnDestroy {
559
562
}
560
563
}
561
564
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
+ */
572
575
private getOverlayInfo (
573
576
component : ElementRef | Type < any > ,
574
- viewContainerRefOrSettings ?: ViewContainerRef | OverlaySettings ) : OverlayInfo | null {
577
+ viewContainerRefOrSettings ?: ViewContainerRef | OverlayCreateSettings ,
578
+ settings ?: OverlaySettings ) : OverlayInfo | null {
575
579
const info : OverlayInfo = { ngZone : this . _zone , transformX : 0 , transformY : 0 } ;
580
+ let overlaySettings = settings ;
576
581
if ( component instanceof ElementRef ) {
577
582
info . elementRef = component ;
583
+ overlaySettings = viewContainerRefOrSettings as OverlaySettings ;
578
584
} else {
579
585
let dynamicComponent : ComponentRef < any > ;
580
586
if ( viewContainerRefOrSettings instanceof ViewContainerRef ) {
581
- dynamicComponent = viewContainerRefOrSettings . createComponent ( component ) ;
587
+ const viewContainerRef = viewContainerRefOrSettings as ViewContainerRef ;
588
+ dynamicComponent = viewContainerRef . createComponent ( component ) ;
582
589
} else {
583
590
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 } ) ;
585
597
this . _appRef . attachView ( dynamicComponent . hostView ) ;
586
598
}
587
599
if ( dynamicComponent . onDestroy ) {
@@ -597,6 +609,7 @@ export class IgxOverlayService implements OnDestroy {
597
609
info . elementRef = { nativeElement : element } ;
598
610
info . componentRef = dynamicComponent ;
599
611
}
612
+ info . settings = Object . assign ( { } , this . _defaultSettings , overlaySettings ) ;
600
613
return info ;
601
614
}
602
615
0 commit comments