import { ComponentFactoryResolver, ComponentRef, Injectable, TemplateRef, Type } from '@angular/core'; import { NbComponentPortal, NbComponentType, NbOverlay, NbOverlayConfig, NbOverlayRef, } from './mapping'; import { NbScrollStrategyOptions } from '../adapter/block-scroll-strategy-adapter'; import { NbLayoutDirectionService } from '../../../services/direction.service'; export type NbOverlayContent = Type | TemplateRef | string; export function patch(container: ComponentRef, containerContext: Object): ComponentRef { Object.assign(container.instance, containerContext); container.changeDetectorRef.detectChanges(); return container; } export function createContainer( ref: NbOverlayRef, container: NbComponentType, context: Object, componentFactoryResolver?: ComponentFactoryResolver, ): ComponentRef { const containerRef = ref.attach(new NbComponentPortal(container, null, null, componentFactoryResolver)); patch(containerRef, context); return containerRef; } @Injectable() export class NbOverlayService { constructor(protected overlay: NbOverlay, protected layoutDirection: NbLayoutDirectionService) { } get scrollStrategies(): NbScrollStrategyOptions { return this.overlay.scrollStrategies; } create(config?: NbOverlayConfig): NbOverlayRef { const overlayRef = this.overlay.create(config); this.layoutDirection.onDirectionChange() .subscribe(dir => overlayRef.setDirection(dir)); return overlayRef; } }