@@ -34,6 +34,7 @@ import {
34
34
} from '@angular/core' ;
35
35
import { AbstractControlDirective } from '@angular/forms' ;
36
36
import { ThemePalette } from '@angular/material/core' ;
37
+ import { _IdGenerator } from '@angular/cdk/a11y' ;
37
38
import { Subject , Subscription , merge } from 'rxjs' ;
38
39
import { takeUntil } from 'rxjs/operators' ;
39
40
import { MAT_ERROR , MatError } from './directives/error' ;
@@ -105,8 +106,6 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS = new InjectionToken<MatFormFieldDef
105
106
'MAT_FORM_FIELD_DEFAULT_OPTIONS' ,
106
107
) ;
107
108
108
- let nextUniqueId = 0 ;
109
-
110
109
/** Default appearance used by the form field. */
111
110
const DEFAULT_APPEARANCE : MatFormFieldAppearance = 'fill' ;
112
111
@@ -191,6 +190,7 @@ export class MatFormField
191
190
private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
192
191
private _dir = inject ( Directionality ) ;
193
192
private _platform = inject ( Platform ) ;
193
+ private _idGenerator = inject ( _IdGenerator ) ;
194
194
private _defaults = inject < MatFormFieldDefaultOptions > ( MAT_FORM_FIELD_DEFAULT_OPTIONS , {
195
195
optional : true ,
196
196
} ) ;
@@ -305,10 +305,10 @@ export class MatFormField
305
305
_hasTextSuffix = false ;
306
306
307
307
// Unique id for the internal form field label.
308
- readonly _labelId = ` mat-mdc-form-field-label-${ nextUniqueId ++ } ` ;
308
+ readonly _labelId = this . _idGenerator . getId ( ' mat-mdc-form-field-label-' ) ;
309
309
310
310
// Unique id for the hint label.
311
- readonly _hintLabelId = ` mat-mdc-hint-${ nextUniqueId ++ } ` ;
311
+ readonly _hintLabelId = this . _idGenerator . getId ( ' mat-mdc-hint-' ) ;
312
312
313
313
/** State of the mat-hint and mat-error animations. */
314
314
_subscriptAnimationState = '' ;
0 commit comments