import { Component, OnInit, Input } from '@angular/core'; import { CodeDataService } from '../../services/code-data.service'; import { CodeData } from '../../codeData'; @Component({ selector: 'app-example-viewer', templateUrl: './example-viewer.component.html', styleUrls: ['./example-viewer.component.scss'] }) export class ExampleViewerComponent implements OnInit { isShowExample: boolean = false; code_html: string; code_ts: string; code_css: string; noCode: string = ``; @Input() path: string; @Input() title: string = 'Base Title'; constructor(private codeDataService: CodeDataService) {} ngOnInit() { if (this.path) this.getCodeData(this.path); } getCodeData(path) { this.codeDataService.getDocCode(path + '/html.txt', res => { this.code_html = res ? res : this.noCode; }); this.codeDataService.getDocCode(path + '/ts.txt', res => { this.code_ts = res ? res : this.noCode; }); this.codeDataService.getDocCode(path + '/css.txt', res => { this.code_css = res ? res : this.noCode; }); } toggleShowExample() { this.isShowExample = !this.isShowExample; } copyCode(target) { // console.log(target); const selObj = window.getSelection(); // console.log(selObj.toString()); const bool = document.execCommand('selectAll'); } }