Skip to content

Commit ac6f64f

Browse files
author
Your Name
committed
recording
1 parent a447d91 commit ac6f64f

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

au-modal/src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {AuModalModule} from "./au-modal/au-modal.module";
1919
HttpModule,
2020
AuInputModule,
2121
AuTabPanelModule,
22-
AuModalModule
22+
AuModalModule.forRoot()
2323

2424
],
2525
providers: [],

au-modal/src/app/au-modal/au-modal-open-on-click.directive.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import {AfterContentInit, ContentChild, Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core';
1+
import {AfterContentInit, ContentChild, Directive, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
22
import {AuModalComponent} from "./au-modal.component";
3+
import {AuModalService} from "./modal.service";
34

45
@Directive({
56
selector: '[auModalOpenOnClick]'
67
})
7-
export class AuModalOpenOnClickDirective {
8-
9-
8+
export class AuModalOpenOnClickDirective implements OnInit {
109

1110

1211
constructor(private templateRef: TemplateRef<any>,
13-
private viewContainer: ViewContainerRef) {
12+
private viewContainer: ViewContainerRef,
13+
private modalService: AuModalService) {
1414

1515
}
1616

17+
ngOnInit() {
18+
19+
this.modalService.close$.subscribe(() => this.viewContainer.clear());
20+
21+
}
1722

1823
@Input()
1924
set auModalOpenOnClick(els) {

au-modal/src/app/au-modal/au-modal.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="modal-overlay" (click)="closeModal()">
22

3-
<div class="modal-body">
3+
<div class="modal-body" (click)="cancelClick($event)">
44

55

66
<ng-container *ngIf="body else projectContent">

au-modal/src/app/au-modal/au-modal.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component, Input, OnInit, TemplateRef} from '@angular/core';
2+
import {AuModalService} from "./modal.service";
23

34
@Component({
45
selector: 'au-modal',
@@ -10,14 +11,19 @@ export class AuModalComponent implements OnInit {
1011
@Input()
1112
body: TemplateRef<any>;
1213

13-
constructor() {
14+
constructor(private modalService: AuModalService) {
1415
}
1516

1617
ngOnInit() {
1718
}
1819

1920
closeModal() {
21+
this.modalService.close();
22+
}
2023

24+
cancelClick(evt: KeyboardEvent) {
25+
evt.preventDefault();
26+
evt.stopPropagation();
2127
}
2228

2329
}

au-modal/src/app/au-modal/au-modal.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {ModuleWithProviders, NgModule} from '@angular/core';
66
import { CommonModule } from '@angular/common';
77
import { AuModalComponent } from './au-modal.component';
88
import { AuModalOpenOnClickDirective } from './au-modal-open-on-click.directive';
9+
import {AuModalService} from "./modal.service";
910

1011

1112

@@ -20,7 +21,12 @@ export class AuModalModule {
2021

2122

2223

23-
24+
static forRoot(): ModuleWithProviders{
25+
return {
26+
ngModule: AuModalModule,
27+
providers: [AuModalService]
28+
}
29+
}
2430

2531

2632

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Injectable} from '@angular/core';
2+
import {Observable} from "rxjs/Observable";
3+
import {Subject} from "rxjs/Subject";
4+
5+
@Injectable()
6+
export class AuModalService {
7+
8+
private subject = new Subject();
9+
10+
close$: Observable<any> = this.subject.asObservable();
11+
12+
constructor() {
13+
14+
}
15+
16+
close() {
17+
this.subject.next();
18+
}
19+
}

0 commit comments

Comments
 (0)