File

projects/netgrif-components-core/src/lib/dialog/components/prompt-dialog/prompt-dialog.component.ts

Description

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.

Extends

AbstractDialogComponent

Metadata

selector ncc-question-dialog-with-answer
styleUrls ./prompt-dialog.component.scss
templateUrl ./prompt-dialog.component.html

Index

Properties
Methods

Constructor

constructor(dialogRef: MatDialogRef<PromptDialogComponent | DialogResult>, data: DialogData)

Only injecting.

Parameters :
Name Type Optional Description
dialogRef MatDialogRef<PromptDialogComponent | DialogResult> No

Reference to a dialog opened via the MatDialog service.

data DialogData No

Injected data that was passed in to a dialog.

Methods

onClose
onClose(isSubmitted: boolean)
Inherited from AbstractDialogComponent
Parameters :
Name Type Optional
isSubmitted boolean No
Returns : void

Properties

Public data
Type : DialogData
Decorators :
@Inject(MAT_DIALOG_DATA)
Inherited from AbstractDialogComponent
Injected data that was passed in to a dialog.
Public dialogRef
Type : MatDialogRef<PromptDialogComponent | DialogResult>
Inherited from AbstractDialogComponent
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;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""