<!DOCTYPE html>
<html>
<head>
<title>Angular Material Plunker</title>
<!-- Load common libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/typescript/2.1.6/typescript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.7.2/zone.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.47/system.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.2.2/web-animations.min.js"></script>
<!-- Configure SystemJS -->
<script src="config.js"></script>
<script>
System
.import('main.ts')
.catch(console.error.bind(console));
</script>
<!-- Load the Angular Material stylesheet -->
<link href="https://rawgit.com/angular/material2-builds/master/prebuilt-themes/indigo-pink.css" rel="stylesheet">
<style>body { font-family: Roboto, Arial, sans-serif; margin: 0 }</style>
</head>
<body class="mat-app-background">
<example>Loading ngm common dialogs example...</example>
</body>
</html>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->
/* Styles go here */
### ngm common dialogs example demo
/** Add Transpiler for Typescript */
System.config({
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
packages: {
'.': {
defaultExtension: 'ts'
},
'vendor': {
defaultExtension: 'js'
}
}
});
System.config({
map: {
'main': 'main.js',
// Angular specific mappings.
'@angular/core': 'https://unpkg.com/@angular/core/bundles/core.umd.js',
'@angular/common': 'https://unpkg.com/@angular/common/bundles/common.umd.js',
'@angular/compiler': 'https://unpkg.com/@angular/compiler/bundles/compiler.umd.js',
'@angular/animations': "https://unpkg.com/@angular/animations/bundles/animations.umd.js",
'@angular/animations/browser': 'https://unpkg.com/@angular/animations/bundles/animations-browser.umd.js',
'@angular/http': 'https://unpkg.com/@angular/http/bundles/http.umd.js',
'@angular/forms': 'https://unpkg.com/@angular/forms/bundles/forms.umd.js',
'@angular/router': 'https://unpkg.com/@angular/router/bundles/router.umd.js',
'@angular/platform-browser': 'https://unpkg.com/@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/animations': 'https://unpkg.com/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/flex-layout': 'https://unpkg.com/@angular/flex-layout@2.0.0-beta.9/bundles/flex-layout.umd.js',
'@angular/material': 'https://rawgit.com/angular/material2-builds/master/bundles/material.umd.js',
'@angular/cdk': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk.umd.js',
'ngm-common-dialogs': 'https://unpkg.com/ngm-common-dialogs/ngm-common-dialogs.umd.js',
// CDK Secondary entry points
'@angular/cdk/a11y': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-a11y.umd.js',
'@angular/cdk/bidi': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-bidi.umd.js',
'@angular/cdk/coercion': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-coercion.umd.js',
'@angular/cdk/keycodes': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-keycodes.umd.js',
'@angular/cdk/observers': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-observers.umd.js',
'@angular/cdk/platform': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-platform.umd.js',
'@angular/cdk/portal': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-portal.umd.js',
'@angular/cdk/rxjs': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-rxjs.umd.js',
'@angular/cdk/table': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-table.umd.js',
'@angular/cdk/testing': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-testing.umd.js',
'@angular/cdk/overlay': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-overlay.umd.js',
'@angular/cdk/scrolling': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-scrolling.umd.js',
'@angular/cdk/collections': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-collections.umd.js',
'@angular/cdk/stepper': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk-stepper.umd.js',
// Third party libraries
'tslib': 'https://unpkg.com/tslib@1.7.1',
'rxjs': 'https://unpkg.com/rxjs',
},
packages: {
// Thirdparty barrels.
'rxjs': { main: 'index' },
}
});
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
//main entry point
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {NgmCommonDialogsExampleModule} from 'app.ts';
platformBrowserDynamic().bootstrapModule(NgmCommonDialogsExampleModule)
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MdDialogModule, MdButtonModule, MdInputModule, MdProgressSpinnerModule } from '@angular/material';
import { FlexLayoutModule } from "@angular/flex-layout";
import { NgmCommonDialogsModule, CommonDialogService, AlertDialogComponent, ConfirmDialogComponent, PromptDialogComponent, LoadingDialogComponent, CommonDialogService } from 'ngm-common-dialogs';
import { ComponentsExampleComponent } from 'components-example.ts';
import { ServiceExampleComponent } from 'service-example.ts';
import { ExampleComponent } from 'example.ts';
@NgModule({
declarations: [
ComponentsExampleComponent,
ServiceExampleComponent,
ExampleComponent
],
imports: [
CommonModule,
BrowserAnimationsModule,
MdDialogModule,
MdButtonModule,
MdInputModule,
MdProgressSpinnerModule,
FormsModule,
FlexLayoutModule
NgmCommonDialogsModule
],
bootstrap: [ExampleComponent]
})
export class NgmCommonDialogsExampleModule { }
import { Component } from '@angular/core';
import { MdDialog } from '@angular/material';
@Component({
selector: 'example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css']
})
export class ExampleComponent {
}
<div fxLayout="column" fxLayoutAlign="start center">
<h2>Components</h2>
<components-example></components-example>
<h2>Common Dialog Service</h2>
<service-example></service-example>
</div>
button {
margin: 4px;
}
import { Component } from '@angular/core';
import { CommonDialogService } from 'ngm-common-dialogs';
@Component({
selector: 'service-example',
templateUrl: 'service-example.html',
styleUrls: ['service-example.css']
})
export class ServiceExampleComponent {
alertText: string;
confirmText: string;
promptText: string;
loadingText: string;
shouldReject = false;
constructor(private commonDialogService: CommonDialogService) { }
showAlertDialog () {
return this.commonDialogService.showAlert({
title: 'Nice One',
message: 'You just opened an alert dialog',
okButton: 'Yay!',
}).then(() => this.alertText = 'Wow');
}
showConfirmDialog () {
return this.commonDialogService.showConfirm({
title: 'Caution',
message: 'Are you sure you want to do this?',
cancelButton: 'No Way!',
yesButton: 'Absolutely',
})
.then(() => this.confirmText = 'Lets go!')
.catch(() => this.confirmText = 'Maybe next time');
}
showPromptDialog () {
return this.commonDialogService.showPrompt({
title: 'Personality Test',
message: 'What is your favorite dish?',
inputLabel: 'Dish Name',
cancelButton: 'No',
okButton: 'Choose',
})
.then((dishName: string) => this.promptText = dishName);
}
showLoadingDialog() {
return this.commonDialogService.showLoading({
title: 'Be patient...',
promise: new Promise((resolve, reject) => {
setTimeout(() => {
if(this.shouldReject) {
reject();
}
else {
resolve();
}
this.shouldReject = !this.shouldReject;
}, 2000)
})
})
.then(() => this.loadingText = 'It Worked!')
.catch(() => this.loadingText = 'It Failed!');
}
}
<div fxLayout="row">
<div fxLayout="column" fxLayoutAlign="start center">
<button color="primary" md-raised-button (click)="showAlertDialog()">Show Alert Dialog</button>
<span>{{ alertText }}</span>
</div>
<div fxLayout="column" fxLayoutAlign="start center">
<button color="primary" md-raised-button (click)="showConfirmDialog()">Show Confirm Dialog</button>
<span>{{ confirmText }}</span>
</div>
<div fxLayout="column" fxLayoutAlign="start center">
<button color="primary" md-raised-button (click)="showPromptDialog()">Show Prompt Dialog</button>
<span>{{ promptText }}</span>
</div>
<div fxLayout="column" fxLayoutAlign="start center">
<button color="primary" md-raised-button (click)="showLoadingDialog()">Show Loading Dialog</button>
<span>{{ loadingText }}</span>
</div>
</div>
button {
margin: 4px;
}
import { Component } from '@angular/core';
import { MdDialog } from '@angular/material';
import { ConfirmDialogComponent, AlertDialogComponent, PromptDialogComponent, LoadingDialogComponent } from 'ngm-common-dialogs';
@Component({
selector: 'components-example',
templateUrl: 'components-example.html',
styleUrls: ['components-example.css']
})
export class ComponentsExampleComponent {
constructor(private dialogService: MdDialog) { }
showAlertDialog() : void {
this.dialogService.open(AlertDialogComponent, {
data: {
title: 'Nice One',
message: 'You just opened an alert dialog',
okButton: 'Yay!',
}
})
}
showConfirmDialog() : void {
this.dialogService.open(ConfirmDialogComponent, {
data: {
title: 'Caution',
message: 'Are you sure you want to do this?',
cancelButton: 'No Way!',
yesButton: 'Absolutely',
}
})
}
showPromptDialog() : void {
this.dialogService.open(PromptDialogComponent, {
data: {
title: 'Personality Test',
message: 'What is your favorite dish?',
inputLabel: 'Dish Name',
cancelButton: 'No',
okButton: 'Choose',
}
})
}
showLoadingDialog() : void {
this.dialogService.open(LoadingDialogComponent, {
data: {
title: 'Be patient...',
promise: new Promise(resolve => {
setTimeout(() => {
resolve();
}, 2000)
})
}
})
}
}
<div fxLayout="row">
<button color="primary" md-raised-button (click)="showAlertDialog()">Show Alert Dialog</button>
<button color="primary" md-raised-button (click)="showConfirmDialog()">Show Confirm Dialog</button>
<button color="primary" md-raised-button (click)="showPromptDialog()">Show Prompt Dialog</button>
<button color="primary" md-raised-button (click)="showLoadingDialog()">Show Loading Dialog</button>
</div>
button {
margin: 4px;
}