-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdialog.directive.ts
More file actions
29 lines (25 loc) · 966 Bytes
/
dialog.directive.ts
File metadata and controls
29 lines (25 loc) · 966 Bytes
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
import {Component, Input, Output, EventEmitter, HostListener, Directive } from '@angular/core';
import {MdDialogRef, MdDialog, ComponentType, MdDialogConfig} from "@angular/material";
/**
* Used for opening popups and alert messages
*/
@Directive({
selector: '[ngfbDialog]'
})
export class DialogDirective {
@Input() public data: any;
@Input() public component: Component;
@Input() public disableClose: boolean = false;
@Output() public onDialogResult = new EventEmitter<any>();
constructor(public dialog: MdDialog) { }
@HostListener("click", ["$event"]) openDialog() {
const ref: MdDialogRef<Component> = this.dialog.open(
this.component as ComponentType<Component>,
{
disableClose: this.disableClose
} as MdDialogConfig
);
ref.componentInstance['data'] = this.data;
ref.afterClosed().subscribe(result => this.onDialogResult.emit(result));
}
}