Skip to content

bug(MATDIALOG): MatDialogConfig.id not working #24251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
diogodomanski opened this issue Jan 21, 2022 · 3 comments
Closed
1 task

bug(MATDIALOG): MatDialogConfig.id not working #24251

diogodomanski opened this issue Jan 21, 2022 · 3 comments
Labels
needs triage This issue needs to be triaged by the team

Comments

@diogodomanski
Copy link

diogodomanski commented Jan 21, 2022

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I'm trying to set custom IDs for MatDialogRef, but it is not working. Any custom ID is being overriden by default strategy (mat-dialog-)

Reproduction

// loading-dialog.service.ts

@Injectable()
export class LoadingDialogService
{
    private _sequence: number = 0;
    constructor(private _dialog: MatDialog) { }

    openDialog() {
        const dialogRef = this._dialog.open(LoadingDialogComponent, {
            id: `loading-dialog-${this._sequence++}`
        });
        console.log(dialogRef.id); // mat-dialog-0 instead of loading-dialog-0
    }
}

Expected Behavior

DialogRef.id should contain the value passed in id property

Actual Behavior

DialogRef.id value seems to be being ignored and overwritten by default strategy

Environment

  • Angular: 13.1.3
  • CDK/Material: 13.1.3
  • Browser(s): Brave 1.34.80
  • Operating System (e.g. Windows, macOS, Ubuntu): Ubuntu 21.04
@diogodomanski diogodomanski added the needs triage This issue needs to be triaged by the team label Jan 21, 2022
@diogodomanski
Copy link
Author

I've debug MatDialog::open() method and realized that this issue is being caused by the following intructions:

        // If there is a dialog that is currently animating open, return the MatDialogRef of that dialog
        if (this._dialogAnimatingOpen) {
            return this._lastDialogRef;
        }

As I am trying to open a new dialog from another one (inside ngOnInit method) it seems that the MatDialog::open() method is returning the reference for the first opening dialog in both calls.

I put the second call inside a setTimeout() to apply a delay of 1000ms, and the returns of two calls now are different. But that is a terrible workaround.

I hope there would be a more elegant way of managing dialog openings.

@crisbeto
Copy link
Member

Sounds like a duplicate of #24037 which has a pending fix.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

2 participants