1
- import { Injectable , OnDestroy , OnInit } from '@angular/core' ;
2
- import { HttpClient } from '@angular/common/http' ;
3
- import { Observable , Subscription } from 'rxjs' ;
4
- import { map } from 'rxjs/operators' ;
5
- import { DomSanitizer , SafeResourceUrl } from '@angular/platform-browser' ;
6
-
1
+ import { Injectable , OnDestroy , OnInit } from "@angular/core" ;
2
+ import { HttpClient } from "@angular/common/http" ;
3
+ import { Observable , Subscription } from "rxjs" ;
4
+ import { map } from "rxjs/operators" ;
5
+ import { DomSanitizer , SafeResourceUrl } from "@angular/platform-browser" ;
7
6
8
7
export interface CodesandboxIframe {
9
8
src : SafeResourceUrl ;
@@ -13,34 +12,35 @@ export interface CodesandboxIframe {
13
12
export interface CodeSandboxExample {
14
13
title : string ;
15
14
iframe : CodesandboxIframe ;
15
+ visibility : boolean ;
16
16
}
17
17
18
-
19
18
@Injectable ( {
20
- providedIn : ' root'
19
+ providedIn : " root" ,
21
20
} )
22
21
export class CodesandboxServiceService {
23
-
24
22
subscription : Observable < Array < CodeSandboxExample > > ;
25
23
26
- constructor ( private http : HttpClient , protected _sanitizer : DomSanitizer ) {
27
- }
24
+ constructor ( private http : HttpClient , protected _sanitizer : DomSanitizer ) { }
28
25
29
26
getExamples ( examplePathFile : string ) : Observable < Array < CodeSandboxExample > > {
30
- return this . http . get ( examplePathFile ) . pipe ( map ( ( response : any ) => {
31
- let examples : Array < CodeSandboxExample > = [ ] ;
32
- if ( response ?. data && Array . isArray ( response ?. data ) ) {
33
- examples = response ?. data . map ( ( item : any ) => ( {
34
- title : item . title , iframe :
35
- {
36
- src : this . _sanitizer . bypassSecurityTrustResourceUrl ( item . iframe . src ) ,
37
- title : item . iframe . title
38
- } ,
39
- visible : false
40
- } ) ) ;
41
- }
42
- return examples ;
43
- } ) ) ;
27
+ return this . http . get ( examplePathFile ) . pipe (
28
+ map ( ( response : any ) => {
29
+ let examples : Array < CodeSandboxExample > = [ ] ;
30
+ if ( response ?. data && Array . isArray ( response ?. data ) ) {
31
+ examples = response ?. data . map ( ( item : any ) => ( {
32
+ title : item . title ,
33
+ iframe : {
34
+ src : this . _sanitizer . bypassSecurityTrustResourceUrl (
35
+ item . iframe . src
36
+ ) ,
37
+ title : item . iframe . title ,
38
+ } ,
39
+ visibility : item . visibility ?? false ,
40
+ } ) ) ;
41
+ }
42
+ return examples ;
43
+ } )
44
+ ) ;
44
45
}
45
-
46
46
}
0 commit comments