2015-09-03 22:01:36 -07:00
|
|
|
import {bootstrap} from 'angular2/bootstrap';
|
2015-08-04 15:32:17 -07:00
|
|
|
import {
|
2015-09-03 22:01:36 -07:00
|
|
|
bind,
|
2015-08-04 15:32:17 -07:00
|
|
|
ElementRef,
|
|
|
|
ComponentRef,
|
|
|
|
Component,
|
2015-09-03 22:01:36 -07:00
|
|
|
UrlResolver,
|
2015-08-04 15:32:17 -07:00
|
|
|
View,
|
|
|
|
ViewEncapsulation
|
2015-09-03 22:01:36 -07:00
|
|
|
} from 'angular2/core';
|
2015-05-29 16:27:54 -07:00
|
|
|
import {
|
|
|
|
MdDialog,
|
|
|
|
MdDialogRef,
|
|
|
|
MdDialogConfig
|
|
|
|
} from 'angular2_material/src/components/dialog/dialog';
|
2015-04-28 10:56:33 -07:00
|
|
|
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';
|
2015-08-20 14:28:25 -07:00
|
|
|
import {isPresent} from 'angular2/src/core/facade/lang';
|
2015-04-28 10:56:33 -07:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'demo-app',
|
2015-07-29 15:01:22 -07:00
|
|
|
viewBindings: [MdDialog],
|
2015-04-28 10:56:33 -07:00
|
|
|
})
|
|
|
|
@View({
|
|
|
|
templateUrl: './demo_app.html',
|
2015-05-29 16:27:54 -07:00
|
|
|
directives: [],
|
2015-08-28 21:03:19 -07:00
|
|
|
encapsulation: ViewEncapsulation.None,
|
2015-04-28 10:56:33 -07:00
|
|
|
})
|
|
|
|
class DemoApp {
|
|
|
|
dialog: MdDialog;
|
|
|
|
elementRef: ElementRef;
|
|
|
|
dialogRef: MdDialogRef;
|
|
|
|
dialogConfig: MdDialogConfig;
|
|
|
|
lastResult: string;
|
|
|
|
|
2015-06-29 11:15:49 -07:00
|
|
|
constructor(mdDialog: MdDialog, elementRef: ElementRef) {
|
2015-04-28 10:56:33 -07:00
|
|
|
this.dialog = mdDialog;
|
|
|
|
this.elementRef = elementRef;
|
|
|
|
this.dialogConfig = new MdDialogConfig();
|
|
|
|
|
|
|
|
this.dialogConfig.width = '60%';
|
|
|
|
this.dialogConfig.height = '60%';
|
|
|
|
this.lastResult = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
if (isPresent(this.dialogRef)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-29 11:15:49 -07:00
|
|
|
this.dialog.open(SimpleDialogComponent, this.elementRef, this.dialogConfig)
|
2015-05-29 16:27:54 -07:00
|
|
|
.then(ref => {
|
|
|
|
this.dialogRef = ref;
|
|
|
|
ref.instance.numCoconuts = 777;
|
2015-04-28 10:56:33 -07:00
|
|
|
|
2015-05-29 16:27:54 -07:00
|
|
|
ref.whenClosed.then(result => {
|
|
|
|
this.dialogRef = null;
|
|
|
|
this.lastResult = result;
|
|
|
|
});
|
|
|
|
});
|
2015-04-28 10:56:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'simple-dialog',
|
2015-09-30 20:59:23 -07:00
|
|
|
inputs: ['numCoconuts'],
|
2015-04-28 10:56:33 -07:00
|
|
|
})
|
|
|
|
@View({
|
2015-08-28 21:03:19 -07:00
|
|
|
encapsulation: ViewEncapsulation.None,
|
2015-04-28 10:56:33 -07:00
|
|
|
template: `
|
|
|
|
<h2>This is the dialog content</h2>
|
|
|
|
<p>There are {{numCoconuts}} coconuts.</p>
|
|
|
|
<p>Return: <input (input)="updateValue($event)"></p>
|
|
|
|
<button type="button" (click)="done()">Done</button>
|
2015-07-24 15:28:44 -07:00
|
|
|
`
|
2015-04-28 10:56:33 -07:00
|
|
|
})
|
|
|
|
class SimpleDialogComponent {
|
|
|
|
numCoconuts: number;
|
|
|
|
dialogRef: MdDialogRef;
|
|
|
|
toReturn: string;
|
|
|
|
|
|
|
|
constructor(dialogRef: MdDialogRef) {
|
|
|
|
this.numCoconuts = 0;
|
|
|
|
this.dialogRef = dialogRef;
|
|
|
|
this.toReturn = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
updateValue(event) {
|
|
|
|
this.toReturn = event.target.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
done() {
|
|
|
|
this.dialogRef.close(this.toReturn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
commonDemoSetup();
|
2015-07-27 14:15:02 -07:00
|
|
|
bootstrap(DemoApp, [bind(UrlResolver).toValue(new DemoUrlResolver())]);
|
2015-04-28 10:56:33 -07:00
|
|
|
}
|