Last active
July 28, 2019 10:36
-
-
Save arturovt/5aed9ff8c93eb66f52456638576b3891 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| NgModule, | |
| ComponentFactoryResolver, | |
| Injector, | |
| ViewContainerRef, | |
| ApplicationRef, | |
| ComponentRef | |
| } from '@angular/core'; | |
| import { CommonModule } from '@angular/common'; | |
| import { DomPortalHost, ComponentPortal } from '@angular/cdk/portal'; | |
| import { CarouselComponent } from './carousel.component'; | |
| @NgModule({ | |
| imports: [CommonModule], | |
| declarations: [CarouselComponent] | |
| }) | |
| export class CarouselModule { | |
| constructor( | |
| private resolver: ComponentFactoryResolver, | |
| private app: ApplicationRef, | |
| private injector: Injector | |
| ) {} | |
| public renderCarousel(viewContainerRef: ViewContainerRef): ComponentRef<CarouselComponent> { | |
| const host = new DomPortalHost( | |
| viewContainerRef.element.nativeElement, | |
| this.resolver, | |
| this.app, | |
| this.injector | |
| ); | |
| const portal = new ComponentPortal( | |
| CarouselComponent, | |
| viewContainerRef, | |
| this.injector, | |
| this.resolver | |
| ); | |
| const componentRef = portal.attach(host); | |
| componentRef.changeDetectorRef.markForCheck(); | |
| return componentRef; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment