@@ -22,6 +22,7 @@ import {MatDialogRef} from './dialog-ref';
22
22
import { defer , Observable , Subject } from 'rxjs' ;
23
23
import { Dialog , DialogConfig } from '@angular/cdk/dialog' ;
24
24
import { startWith } from 'rxjs/operators' ;
25
+ import { _IdGenerator } from '@angular/cdk/a11y' ;
25
26
26
27
/** Injection token that can be used to access the data that was passed in to a dialog. */
27
28
export const MAT_DIALOG_DATA = new InjectionToken < any > ( 'MatMdcDialogData' ) ;
@@ -65,9 +66,6 @@ export const MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = {
65
66
useFactory : MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY ,
66
67
} ;
67
68
68
- // Counter for unique dialog ids.
69
- let uniqueId = 0 ;
70
-
71
69
/**
72
70
* Service to open Material Design modal dialogs.
73
71
*/
@@ -77,6 +75,7 @@ export class MatDialog implements OnDestroy {
77
75
private _defaultOptions = inject < MatDialogConfig > ( MAT_DIALOG_DEFAULT_OPTIONS , { optional : true } ) ;
78
76
private _scrollStrategy = inject ( MAT_DIALOG_SCROLL_STRATEGY ) ;
79
77
private _parentDialog = inject ( MatDialog , { optional : true , skipSelf : true } ) ;
78
+ private _idGenerator = inject ( _IdGenerator ) ;
80
79
protected _dialog = inject ( Dialog ) ;
81
80
82
81
private readonly _openDialogsAtThisLevel : MatDialogRef < any > [ ] = [ ] ;
@@ -154,7 +153,7 @@ export class MatDialog implements OnDestroy {
154
153
) : MatDialogRef < T , R > {
155
154
let dialogRef : MatDialogRef < T , R > ;
156
155
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-' ) ;
158
157
config . scrollStrategy = config . scrollStrategy || this . _scrollStrategy ( ) ;
159
158
160
159
const cdkRef = this . _dialog . open < R , D , T > ( componentOrTemplateRef , {
0 commit comments