aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/shared/shared-custom-markup/custom-markup-container.component.ts
blob: 4e802b14dd0f20795294922dd20fc25d2645a460 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12




                                                                                  
                                                         





                                                                           

                   








                                                    



                                                                                                       
 



                          
 
import { Component, ElementRef, Input, OnChanges, ViewChild } from '@angular/core'
import { CustomMarkupService } from './custom-markup.service'

@Component({
  selector: 'my-custom-markup-container',
  templateUrl: './custom-markup-container.component.html'
})
export class CustomMarkupContainerComponent implements OnChanges {
  @ViewChild('contentWrapper') contentWrapper: ElementRef<HTMLInputElement>

  @Input() content: string

  displayed = false

  constructor (
    private customMarkupService: CustomMarkupService
  ) { }

  async ngOnChanges () {
    await this.buildElement()
  }

  private async buildElement () {
    if (!this.content) return

    const { rootElement, componentsLoaded } = await this.customMarkupService.buildElement(this.content)
    this.contentWrapper.nativeElement.appendChild(rootElement)

    await componentsLoaded

    this.displayed = true
  }
}