Last active
July 28, 2019 09:42
-
-
Save arturovt/7c03685b430bee62fcc6b1a381ceb6a1 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: ` | |
<ng-container #carousel></ng-container> | |
<button (click)="showCarousel()">Show carousel</button> | |
`, | |
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); | |
const componentFactory = carouselModule.resolveCarouselComponentFactory(); | |
const componentRef = this.carousel.createComponent(componentFactory); | |
componentRef.changeDetectorRef.markForCheck(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment