angular / angular/components

(Dialog) Component-less alert and confirm dialogs

Open
#17,048 5 comments 21 reactions 0 assignees View on GitHub
area: material/dialog feature needs: discussion P5
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

#### Feature Description

My proposal is to create one or two methods on the `MatDialog` provider/controller to allow component-less alert and confirm dialogs, for example:

// Alert dialog
this.dialog.alert({
title: 'Forbidden',
message: 'The resource you are trying to access is forbidden.',
okButton: 'OK'
})

// Confirm dialog
this.dialog.confirm({
title: 'Server error',
message: 'The server is currently in maintenance.',
confirmButton: 'Retry',
cancelButton: 'Cancel'
})

Alternatively, both `alert` and `confirm` could be on a single method:

this.dialog.alert({
title: 'The title',
message: 'The message',
confirmButton: 'OK', // Optional, only for confirm
dismissButton: 'Dismiss'
}).afterClose().subscribe((result: boolean) => console.log); // True if confirm, false if dismiss.

#### Use Case

Currently, we have to create a component for every dialog, event the simplest dialog. This is painful and useless in most cases. Other alternatives (what I do) is to create a `AlertService` that does it for me. But makes no sense maintain it if it could be a simple feature of `MatDialog`

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing MatDialog provider/controller and the current component-based dialog flow. Compare the proposed alert and confirm APIs, including button labels and the boolean close result. Done means the component-less behavior and API choice are defined and implemented for both dialog outcomes.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.