import { Component, ComponentFactoryResolver, ComponentRef, Input, OnDestroy, OnInit, ViewChild, ViewContainerRef, } from '@angular/core' import { CopierService } from '../../services/copier.service' @Component({ selector: 'app-docs-section', template: `

{{title}}

Example

Files


            
`, }) export class DocsSectionComponent implements OnInit, OnDestroy { @Input() public title @Input() public description @Input() public component @Input() public files: { file: string; content: string }[] = [] public show = {} @ViewChild('demo', { read: ViewContainerRef }) demoRef: ViewContainerRef demoComponentRef: ComponentRef constructor( private componentFactoryResolver: ComponentFactoryResolver, private copier: CopierService, ) {} ngOnInit() { const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.component) this.demoComponentRef = this.demoRef.createComponent(componentFactory) } ngOnDestroy() { if (this.demoComponentRef) { this.demoComponentRef.destroy() } } copySource(content) { this.copier.copyText(content.innerText); } toggle(e, file) { e.preventDefault() this.show[file] = !this.show[file] } }