File

src/directives/dialog.directive.ts

Description

Used for opening popups and alert messages

Metadata

selector [ngfbDialog]

Inputs

component

Type: Component

data

Type: any

disableClose

Type: boolean

Default value: false

Outputs

onDialogResult $event type: EventEmitter

Constructor

constructor(dialog: MdDialog)

Methods

openDialog
openDialog()
Returns: void

Properties

dialog
dialog: MdDialog
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));
    }
}

results matching ""

    No results matching ""