projects/netgrif-components-core/src/lib/dialog/components/prompt-dialog/prompt-dialog.component.ts
Question modal dialog with its own layout (which asks the user a question and wait for the answer) based on a material design that injected data and inherits from an AbstractDialog.
selector | ncc-question-dialog-with-answer |
styleUrls | ./prompt-dialog.component.scss |
templateUrl | ./prompt-dialog.component.html |
Properties |
|
Methods |
constructor(dialogRef: MatDialogRef<PromptDialogComponent | DialogResult>, data: DialogData)
|
||||||||||||
Only injecting.
Parameters :
|
onClose | ||||||
onClose(isSubmitted: boolean)
|
||||||
Inherited from
AbstractDialogComponent
|
||||||
Defined in
AbstractDialogComponent:32
|
||||||
Parameters :
Returns :
void
|
Public data |
Type : DialogData
|
Decorators :
@Inject(MAT_DIALOG_DATA)
|
Inherited from
AbstractDialogComponent
|
Defined in
AbstractDialogComponent:28
|
Injected data that was passed in to a dialog.
|
Public dialogRef |
Type : MatDialogRef<PromptDialogComponent | DialogResult>
|
Inherited from
AbstractDialogComponent
|
Defined in
AbstractDialogComponent:27
|
Reference to a dialog opened via the MatDialog service.
|
Public disableButton |
Default value : true
|
Set submit button to disabled or enabled according to the user answer. |
Public prompt |
Type : string
|
Public submitClick |
Type : boolean
|
import {Component, Inject} from '@angular/core';
import {AbstractDialogComponent} from '../../models/abstract-dialog.component';
import {DialogResult} from '../../models/DialogResult';
import {DialogData} from '../../models/DialogData';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
/**
* Question modal dialog with its own layout (which asks the user a question and wait for the answer)
* based on a material design that injected data and inherits from an [AbstractDialog]{@link AbstractDialogComponent}.
*/
@Component({
selector: 'ncc-question-dialog-with-answer',
templateUrl: './prompt-dialog.component.html',
styleUrls: ['./prompt-dialog.component.scss']
})
export class PromptDialogComponent extends AbstractDialogComponent<PromptDialogComponent> {
/** Set submit button to disabled or enabled according to the user answer. */
public disableButton = true;
public prompt: string;
public submitClick: boolean;
/**
* Only injecting.
* @param dialogRef Reference to a dialog opened via the MatDialog service.
* @param data Injected data that was passed in to a dialog.
*/
constructor(public dialogRef: MatDialogRef<PromptDialogComponent, DialogResult>,
@Inject(MAT_DIALOG_DATA) public data: DialogData) {
super(dialogRef, data);
}
onClose(isSubmitted: boolean) {
this.dialogRef.close(isSubmitted ? {
prompt: this.prompt
} : {});
}
}
<h1 mat-dialog-title>{{data.title}}</h1>
<div mat-dialog-content class="dialog-container dialog-content-margin netgrif-input netgrif-input-fix">
<span>{{data.content}}</span>
<br>
<mat-form-field class="dialog-prompt-margin" appearance="outline">
<mat-label>{{data.placeholder}}</mat-label>
<input matInput [(ngModel)]="prompt" (ngModelChange)="disableButton = !prompt || prompt.trim().length === 0">
</mat-form-field>
</div>
<mat-dialog-actions fxLayoutAlign="end">
<button mat-button (click)="onClose(false)">{{ 'dialog.close' | translate}}</button>
<button mat-flat-button color="primary" [disabled]="disableButton" (click)="onClose(true)">{{ 'dialog.submit' | translate}}</button>
</mat-dialog-actions>
./prompt-dialog.component.scss
.dialog-prompt-margin {
margin-top: 16px;
}