Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Last active February 10, 2016 16:47
Show Gist options
  • Save vladimir-ivanov/a5d3f9015807a9fe7931 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/a5d3f9015807a9fe7931 to your computer and use it in GitHub Desktop.
md-dialog sngular2 with content
import {Input, OnInit, Component, Attribute, Output, EventEmitter} from "angular2/core";
import {KeyCodes} from "ng2-material/core/key_codes";
import {OnChanges} from "../../../../node_modules/angular2/ts/src/core/linker/interfaces";
@Component({
selector: "md-dialog-advanced",
host: {
"(body:keydown)": "documentKeypress($event)"
},
template: `
<md-backdrop class="md-backdrop md-opaque md-active" *ngIf="!isClosed" (click)="close()"></md-backdrop>
<md-dialog-container *ngIf="!isClosed" class="md-dialog md-dialog-absolute md-active md-content-overflow md-transition-in" tabindex="0">
<md-toolbar>
<div class="md-toolbar-tools">
<h2>{{title}}</h2>
<img src="/img/ic_highlight_off_white_36dp.png" class="close-button" alt="" (click)="close()" role="button" tabindex="0">
</div>
</md-toolbar>
<md-dialog-content><ng-content></ng-content></md-dialog-content>
</md-dialog-container>
`
})
export class MdDialogAdvanced {
@Input()
isClosed = true;
@Output()
isClosedChange:EventEmitter<boolean> = new EventEmitter(); // an event emitter
title;
constructor(@Attribute("title")title) {
this.title = title;
}
close() {
this.isClosed = true;
this.isClosedChange.emit(this.isClosed);
}
open() {
this.isClosed = false;
this.isClosedChange.emit(this.isClosed);
}
documentKeypress(event:KeyboardEvent) {
if (event.keyCode === KeyCodes.ESCAPE) {
this.isClosed = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment