1
+ /*
2
+ * Angular 2 decorators and services
3
+ */
4
+ import { Component , Input , OnInit , ElementRef , Injector } from '@angular/core' ;
5
+ import * as path from 'path' ;
6
+
7
+ /*
8
+ * App Component
9
+ * Top Level Component
10
+ */
11
+ @Component ( {
12
+ // The selector is what angular internally uses
13
+ selector : 'cb-iframe' , // <app></app>
14
+ // The template for our app
15
+ template : `<iframe scrolling="no" frameBorder="0" style="width: '100%', height: '100%'"></iframe>
16
+ `
17
+ } )
18
+ export class IframeComponent implements OnInit {
19
+ @Input ( ) basePath : string ;
20
+ userBundle : string ;
21
+ element : HTMLElement ;
22
+ iframe : any ;
23
+
24
+ constructor ( private _ref : ElementRef ) {
25
+ }
26
+
27
+ ngOnInit ( ) {
28
+ //console.log(this.basePath);
29
+ //this.userBundle = path.join(this.basePath, 'user-bundle.js');
30
+ this . userBundle = '' ;
31
+ this . element = this . _ref . nativeElement ;
32
+ this . iframe = this . element . children [ 0 ] ;
33
+ console . log ( this . iframe ) ;
34
+ const doc = this . iframe . contentDocument ;
35
+ doc . open ( ) ;
36
+ // eslint-disable-next-line max-len
37
+ doc . write ( this . createHTML ( this . userBundle ) ) ;
38
+ doc . close ( ) ;
39
+ }
40
+
41
+ createHTML ( userbundle ) {
42
+ return `<!DOCTYPE html>
43
+ <html style="height: 100%; width: 100%; margin: 0; padding: 0;">
44
+ <head>
45
+ </head>
46
+ <body style="height: 100%; width: 100%; margin: 0; padding: 0;">
47
+ <div
48
+ id="root"
49
+ style="
50
+ display: flex;
51
+ justify-content: center;
52
+ align-items: center;
53
+ height: 100vh;
54
+ ">
55
+ <cb-app>
56
+ <div class="new-element">
57
+ <cb-button [text]="Loading Component" [isRed]="false"></cb-button>
58
+ </div>
59
+ </cb-app>
60
+
61
+ </div>
62
+ <script type="text/javascript" src="http://localhost:3000/main.js"></script></body>
63
+ </body>
64
+ </html>` ;
65
+ }
66
+ }
0 commit comments