Skip to content

Commit bcc8da2

Browse files
authored
Add files via upload
1 parent 63a8e1b commit bcc8da2

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Directive, ViewContainerRef } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[datacontainer]',
5+
})
6+
export class DatacontainerDirective {
7+
constructor(public viewContainerRef: ViewContainerRef) {
8+
9+
10+
}
11+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1+
.modal{
2+
display: block;
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- Modal -->
2+
<div class="modal fade in" role="dialog" tabindex="-1" aria-hidden="true" #thisModal>
3+
<div class="modal-dialog">
4+
5+
<!-- Modal content-->
6+
<div class="modal-content">
7+
<div class="modal-header">
8+
<button type="button" class="close" (click)="closeModal()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
9+
<h4 class="modal-title">{{ title }}</h4>
10+
</div>
11+
<div class="modal-body">
12+
<div #datacontainer></div>
13+
</div>
14+
<div class="modal-footer">
15+
<button type="button" class="btn btn-default" (click)="closeModal()">Close</button>
16+
</div>
17+
</div>
18+
19+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ModalDialogComponent } from './modal-dialog.component';
4+
5+
describe('ModalDialogComponent', () => {
6+
let component: ModalDialogComponent;
7+
let fixture: ComponentFixture<ModalDialogComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ ModalDialogComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ModalDialogComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
Component, Input, OnInit,
3+
ComponentFactoryResolver, ViewContainerRef, ViewChild, ElementRef, Renderer2, AfterContentInit
4+
} from '@angular/core';
5+
import { ComponentLoaderService } from '../component-loader.service';
6+
7+
8+
@Component({
9+
selector: 'modal-dialog',
10+
templateUrl: './modal-dialog.component.html',
11+
styleUrls: ['./modal-dialog.component.css']
12+
})
13+
14+
export class ModalDialogComponent implements OnInit, AfterContentInit {
15+
@Input() title: string;
16+
@Input() componentData: string;
17+
@Input() componentName: any;
18+
public name : any;
19+
20+
@ViewChild('datacontainer', { read: ViewContainerRef }) entry: ViewContainerRef;
21+
22+
constructor(
23+
private el: ElementRef,
24+
private ren: Renderer2,
25+
private viewContainer: ViewContainerRef,
26+
private resolver: ComponentFactoryResolver,
27+
private loaderService :ComponentLoaderService
28+
) {}
29+
30+
public div = this.ren.createElement('div');
31+
32+
ngOnInit() {
33+
34+
}
35+
36+
ngAfterContentInit(){
37+
this.ren.addClass(this.el.nativeElement.ownerDocument.body, 'modal-open');
38+
this.ren.appendChild(this.el.nativeElement, this.div);
39+
this.ren.setAttribute(this.div , 'class', 'modal-backdrop fade in');
40+
this.createModalPopup();
41+
}
42+
43+
createModalPopup(){
44+
const name = this.loaderService.getComponent(this.componentName);
45+
console.log("Component Name => ",name);
46+
const myFactory = this.resolver.resolveComponentFactory(<any>name);
47+
const myRef = this.entry.createComponent(myFactory);
48+
myRef.instance['data'] = this.componentData;
49+
}
50+
51+
closeModal() {
52+
this.ren.removeClass(this.el.nativeElement.ownerDocument.body, 'modal-open');
53+
this.ren.removeChild(this.el.nativeElement, this.div);
54+
this.el.nativeElement.remove();
55+
}
56+
57+
58+
}
59+

0 commit comments

Comments
 (0)