-
Notifications
You must be signed in to change notification settings - Fork 949
/
tabbed-example-block.component.ts
48 lines (41 loc) · 1.24 KB
/
tabbed-example-block.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Input,
Output,
EventEmitter,
} from '@angular/core';
import { forkJoin, of as observableOf, Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { NgdCodeLoaderService } from '../../../@theme/services';
import { NgdExampleView } from '../../enum.example-view';
@Component({
selector: 'ngd-tabbed-example-block',
styleUrls: ['./tabbed-example-block.component.scss'],
templateUrl: './tabbed-example-block.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NgdTabbedExampleBlockComponent {
@Input() hasViewSwitch = false;
@Output() changeView = new EventEmitter<NgdExampleView>();
examples = [];
@Input()
set content({ files }) {
this.examples = files;
this.examples[0].active = true;
}
constructor(private codeLoader: NgdCodeLoaderService, private cd: ChangeDetectorRef) {
}
switchToLiveView() {
this.changeView.emit(NgdExampleView.LIVE);
}
private load(path): Observable<any> {
const extension = path.split('.').pop();
return this.codeLoader.load(path)
.pipe(
map(code => ({ code, path, extension })),
catchError(e => observableOf('')),
);
}
}