]>
Commit | Line | Data |
---|---|---|
8ee25e17 C |
1 | import { Component, ElementRef, Input, OnChanges, ViewChild } from '@angular/core' |
2 | import { CustomMarkupService } from './custom-markup.service' | |
3 | ||
4 | @Component({ | |
5 | selector: 'my-custom-markup-container', | |
24893b52 | 6 | templateUrl: './custom-markup-container.component.html' |
8ee25e17 C |
7 | }) |
8 | export class CustomMarkupContainerComponent implements OnChanges { | |
789ba349 | 9 | @ViewChild('contentWrapper', { static: true }) contentWrapper: ElementRef<HTMLInputElement> |
8ee25e17 | 10 | |
789ba349 | 11 | @Input() content: string | HTMLDivElement |
8ee25e17 | 12 | |
0ca454e3 C |
13 | displayed = false |
14 | ||
8ee25e17 C |
15 | constructor ( |
16 | private customMarkupService: CustomMarkupService | |
17 | ) { } | |
18 | ||
19 | async ngOnChanges () { | |
789ba349 | 20 | await this.rebuild() |
8ee25e17 C |
21 | } |
22 | ||
789ba349 C |
23 | private async rebuild () { |
24 | if (this.content instanceof HTMLDivElement) { | |
25 | return this.loadElement(this.content) | |
26 | } | |
0ca454e3 C |
27 | |
28 | const { rootElement, componentsLoaded } = await this.customMarkupService.buildElement(this.content) | |
0ca454e3 C |
29 | await componentsLoaded |
30 | ||
789ba349 C |
31 | return this.loadElement(rootElement) |
32 | } | |
33 | ||
34 | private loadElement (el: HTMLDivElement) { | |
35 | this.contentWrapper.nativeElement.appendChild(el) | |
36 | ||
0ca454e3 C |
37 | this.displayed = true |
38 | } | |
8ee25e17 | 39 | } |