DialogServiceMatDemo
A minimal demo to use dialog-service.
- Create new Angular project, install Angular Material and
dialog-service
.
ng new mat-demo --minimal=true
cd mat-demo
ng add @angular/material
npm install dialog-service
-
Import the module
MatDialogServiceModule
inapp.module.ts
. -
Extract template from
app.component.ts
toapp.component.html
. -
Add button to
app.component.html
that when clicked, triggersdoDemo()
in component.
doDemo () {
// simple demo
this.dialogService.withAlert('Hello!')
// simple, form demo
const fields: DialogFormField[] = [
{ title: 'Name' },
{ title: 'Gender', type: 'radio', options: [ 'Male', 'Female' ] },
]
this.dialogService.withConfirm('Start now ok?').pipe(
filter(ok => ok),
switchMap(() => this.dialogService.withForm('Tell Me About Yourself', fields)),
filter(values => values),
tap(values => this.dialogService.withAlert('You?', {
content: `FORM DATA: \n${JSON.stringify(values, null, 2)}`
}))
).subscribe()
}
- Start the app with
ng serve
and click on the 'Demo' button.