Skip to content

Commit dc03cda

Browse files
committed
refactor(cdk/dialog): use ID generator
Switches to using the ID generator service to create unique IDs.
1 parent 27a66c9 commit dc03cda

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/cdk/dialog/dialog.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {of as observableOf, Observable, Subject, defer} from 'rxjs';
2121
import {DialogRef} from './dialog-ref';
2222
import {DialogConfig} from './dialog-config';
2323
import {Directionality} from '@angular/cdk/bidi';
24+
import {_IdGenerator} from '@angular/cdk/a11y';
2425
import {
2526
ComponentType,
2627
Overlay,
@@ -33,16 +34,14 @@ import {startWith} from 'rxjs/operators';
3334
import {DEFAULT_DIALOG_CONFIG, DIALOG_DATA, DIALOG_SCROLL_STRATEGY} from './dialog-injectors';
3435
import {CdkDialogContainer} from './dialog-container';
3536

36-
/** Unique id for the created dialog. */
37-
let uniqueId = 0;
38-
3937
@Injectable({providedIn: 'root'})
4038
export 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

Comments
 (0)