-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathapp.component.ts
More file actions
50 lines (40 loc) · 1.37 KB
/
app.component.ts
File metadata and controls
50 lines (40 loc) · 1.37 KB
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
49
50
import { Component, ViewEncapsulation, ViewChild, OnInit } from '@angular/core';
import { ModalComponent } from '../../src';
const MODAL_CSS: string[] = [
'assets/modal.css', // Default.
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
];
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class AppComponent implements OnInit {
@ViewChild('componentInsideModal') componentInsideModal: ModalComponent;
modalCss = 0; // @See toggleCssInjector()
ngOnInit() {
this.toggleCssInjector();
}
openFromComponent() {
this.componentInsideModal.open();
}
// ToggleCssInjector is just for the sake of the demo, switching between custom and Boostrap
// styles. In your web app you should rather choose one or the other.
// Web styles reside in ./modal.css
// Alternatively you can pick Boostrap
toggleCssInjector() {
const prev = document.getElementById('injected');
if (prev) {
prev.parentNode.removeChild(prev);
}
const head = document.head;
const link = document.createElement('link');
link.id = 'injected';
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = MODAL_CSS[this.modalCss];
head.appendChild(link);
this.modalCss = (this.modalCss + 1) % MODAL_CSS.length;
}
}