Created
July 28, 2019 10:50
-
-
Save arturovt/9fa526b635eb6d5bd8513abb24c3cff1 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 { | |
Component, | |
ChangeDetectionStrategy, | |
ɵcreateInjector as createInjector, | |
Injector, | |
ViewChild, | |
ViewContainerRef | |
} from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
template: ` | |
<div #carousel></div> | |
<button (click)="showCarousel()">Show carousel</button> | |
`, | |
styles: [ | |
` | |
button { | |
border: 2px solid crimson; | |
background: transparent; | |
font-size: 24px; | |
font-family: monospace; | |
padding: 10px; | |
cursor: pointer; | |
} | |
` | |
], | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class AppComponent { | |
@ViewChild('carousel', { read: ViewContainerRef, static: true }) | |
public carousel: ViewContainerRef; | |
constructor(private injector: Injector) {} | |
public showCarousel(): void { | |
import('./carousel/carousel.module').then(({ CarouselModule }) => { | |
const injector = createInjector(CarouselModule, this.injector); | |
const carouselModule = injector.get(CarouselModule); | |
carouselModule.renderCarousel(this.carousel); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment