@@ -22,6 +22,7 @@ import {MatDialogRef} from './dialog-ref';
2222import { defer , Observable , Subject } from 'rxjs' ;
2323import { Dialog , DialogConfig } from '@angular/cdk/dialog' ;
2424import { startWith } from 'rxjs/operators' ;
25+ import { _IdGenerator } from '@angular/cdk/a11y' ;
2526
2627/** Injection token that can be used to access the data that was passed in to a dialog. */
2728export const MAT_DIALOG_DATA = new InjectionToken < any > ( 'MatMdcDialogData' ) ;
@@ -65,9 +66,6 @@ export const MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = {
6566 useFactory : MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY ,
6667} ;
6768
68- // Counter for unique dialog ids.
69- let uniqueId = 0 ;
70-
7169/**
7270 * Service to open Material Design modal dialogs.
7371 */
@@ -77,6 +75,7 @@ export class MatDialog implements OnDestroy {
7775 private _defaultOptions = inject < MatDialogConfig > ( MAT_DIALOG_DEFAULT_OPTIONS , { optional : true } ) ;
7876 private _scrollStrategy = inject ( MAT_DIALOG_SCROLL_STRATEGY ) ;
7977 private _parentDialog = inject ( MatDialog , { optional : true , skipSelf : true } ) ;
78+ private _idGenerator = inject ( _IdGenerator ) ;
8079 protected _dialog = inject ( Dialog ) ;
8180
8281 private readonly _openDialogsAtThisLevel : MatDialogRef < any > [ ] = [ ] ;
@@ -154,7 +153,7 @@ export class MatDialog implements OnDestroy {
154153 ) : MatDialogRef < T , R > {
155154 let dialogRef : MatDialogRef < T , R > ;
156155 config = { ...( this . _defaultOptions || new MatDialogConfig ( ) ) , ...config } ;
157- config . id = config . id || ` mat-mdc-dialog-${ uniqueId ++ } ` ;
156+ config . id = config . id || this . _idGenerator . getId ( ' mat-mdc-dialog-' ) ;
158157 config . scrollStrategy = config . scrollStrategy || this . _scrollStrategy ( ) ;
159158
160159 const cdkRef = this . _dialog . open < R , D , T > ( componentOrTemplateRef , {
0 commit comments