templateUrl: './custom-markup-container.component.html'
})
export class CustomMarkupContainerComponent implements OnChanges {
- @ViewChild('contentWrapper') contentWrapper: ElementRef<HTMLInputElement>
+ @ViewChild('contentWrapper', { static: true }) contentWrapper: ElementRef<HTMLInputElement>
- @Input() content: string
+ @Input() content: string | HTMLDivElement
+
+ displayed = false
constructor (
private customMarkupService: CustomMarkupService
) { }
async ngOnChanges () {
- await this.buildElement()
+ await this.rebuild()
}
- private async buildElement () {
- const element = await this.customMarkupService.buildElement(this.content)
- this.contentWrapper.nativeElement.appendChild(element)
+ private async rebuild () {
+ if (this.content instanceof HTMLDivElement) {
+ return this.loadElement(this.content)
+ }
+
+ const { rootElement, componentsLoaded } = await this.customMarkupService.buildElement(this.content)
+ await componentsLoaded
+
+ return this.loadElement(rootElement)
}
+ private loadElement (el: HTMLDivElement) {
+ this.contentWrapper.nativeElement.appendChild(el)
+
+ this.displayed = true
+ }
}