Last active
October 9, 2021 19:49
-
-
Save ssougnez/00da05f45aa1c556547fc69fb6f90e31 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 { | |
| AfterViewInit, | |
| Component, | |
| ComponentFactoryResolver, | |
| Input, | |
| ViewChild, | |
| ViewContainerRef, | |
| } from '@angular/core'; | |
| import { BaseHistoryEntryComponent } from './base-history-entry.component'; | |
| import { GetHistoryEntryComponent } from './history-entry-type.decorator'; | |
| import { HistoryEntry } from './history-entry.model'; | |
| @Component({ | |
| selector: 'generic-history-entry', | |
| template: `<ng-template #host></ng-template>`, | |
| }) | |
| export class GenericHistoryEntryComponent implements AfterViewInit { | |
| @Input() | |
| public entry: HistoryEntry; | |
| @ViewChild('host', { read: ViewContainerRef }) | |
| public hostRef: ViewContainerRef; | |
| constructor(private _cfr: ComponentFactoryResolver) {} | |
| public ngAfterViewInit() { | |
| const componentType = GetHistoryEntryComponent(this.entry.type); | |
| const factory = this._cfr.resolveComponentFactory(componentType); | |
| const component = this.hostRef.createComponent(factory); | |
| const instance = component.instance as BaseHistoryEntryComponent<any>; | |
| instance.data = this.entry.data; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment