@@ -21,6 +21,7 @@ import {of as observableOf, Observable, Subject, defer} from 'rxjs';
2121import { DialogRef } from './dialog-ref' ;
2222import { DialogConfig } from './dialog-config' ;
2323import { Directionality } from '@angular/cdk/bidi' ;
24+ import { _IdGenerator } from '@angular/cdk/a11y' ;
2425import {
2526 ComponentType ,
2627 Overlay ,
@@ -33,16 +34,14 @@ import {startWith} from 'rxjs/operators';
3334import { DEFAULT_DIALOG_CONFIG , DIALOG_DATA , DIALOG_SCROLL_STRATEGY } from './dialog-injectors' ;
3435import { CdkDialogContainer } from './dialog-container' ;
3536
36- /** Unique id for the created dialog. */
37- let uniqueId = 0 ;
38-
3937@Injectable ( { providedIn : 'root' } )
4038export class Dialog implements OnDestroy {
4139 private _overlay = inject ( Overlay ) ;
4240 private _injector = inject ( Injector ) ;
4341 private _defaultOptions = inject < DialogConfig > ( DEFAULT_DIALOG_CONFIG , { optional : true } ) ;
4442 private _parentDialog = inject ( Dialog , { optional : true , skipSelf : true } ) ;
4543 private _overlayContainer = inject ( OverlayContainer ) ;
44+ private _idGenerator = inject ( _IdGenerator ) ;
4645
4746 private _openDialogsAtThisLevel : DialogRef < any , any > [ ] = [ ] ;
4847 private readonly _afterAllClosedAtThisLevel = new Subject < void > ( ) ;
@@ -110,7 +109,7 @@ export class Dialog implements OnDestroy {
110109 DialogRef < R , C >
111110 > ;
112111 config = { ...defaults , ...config } ;
113- config . id = config . id || ` cdk-dialog-${ uniqueId ++ } ` ;
112+ config . id = config . id || this . _idGenerator . getId ( ' cdk-dialog-' ) ;
114113
115114 if (
116115 config . id &&
0 commit comments