Instantly share code, notes, and snippets.

Embed
What would you like to do?
dialog.component
<button md-raised-button (click)="onClickEvent()">Open</button>
<br>
{{result}}
import { Component, OnInit } from '@angular/core';
import {MdDialog} from '@angular/material';
import {HelloDialogComponent} from '../hello-dialog/hello-dialog.component';
@Component({
selector: 'app-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.css']
})
export class DialogComponent implements OnInit {
result : any ;
constructor(public mdDialog : MdDialog) { }
ngOnInit() {}
onClickEvent() : void {
let dialog = this.mdDialog.open(HelloDialogComponent, {
'data' : {'title': 'HelloWorld!!'},
'height' : '300px',
'width' : '500px',
'disableClose' : false
});
dialog.afterClosed().subscribe( (result) => {
console.log('afterClosed');
console.log(result);
this.result = result;
});
}
}
<h2 md-dialog-title>{{data.title}}</h2>
<md-dialog-content>
Waga high ha cat dearu...
</md-dialog-content>
<md-dialog-actions>
<button md-raised-button (click)="onClickOkButton()">OK</button>
<button md-raised-button md-dialog-close="cancel">キャンセル</button>
</md-dialog-actions>
import { Component, OnInit, Inject} from '@angular/core';
import {MD_DIALOG_DATA, MdDialogRef} from '@angular/material';
@Component({
selector: 'app-hello-dialog',
templateUrl: './hello-dialog.component.html',
styleUrls: ['./hello-dialog.component.css']
})
export class HelloDialogComponent implements OnInit {
constructor(
@Inject(MD_DIALOG_DATA) public data : any,
public mdDialogRef : MdDialogRef<HelloDialogComponent>) { }
ngOnInit() {
console.dir(this);
}
onClickOkButton() : void {
this.mdDialogRef.close('OK!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment