@@ -34,6 +34,7 @@ import {
3434} from '@angular/core' ;
3535import { AbstractControlDirective } from '@angular/forms' ;
3636import { ThemePalette } from '@angular/material/core' ;
37+ import { _IdGenerator } from '@angular/cdk/a11y' ;
3738import { Subject , Subscription , merge } from 'rxjs' ;
3839import { takeUntil } from 'rxjs/operators' ;
3940import { MAT_ERROR , MatError } from './directives/error' ;
@@ -105,8 +106,6 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS = new InjectionToken<MatFormFieldDef
105106 'MAT_FORM_FIELD_DEFAULT_OPTIONS' ,
106107) ;
107108
108- let nextUniqueId = 0 ;
109-
110109/** Default appearance used by the form field. */
111110const DEFAULT_APPEARANCE : MatFormFieldAppearance = 'fill' ;
112111
@@ -191,6 +190,7 @@ export class MatFormField
191190 private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
192191 private _dir = inject ( Directionality ) ;
193192 private _platform = inject ( Platform ) ;
193+ private _idGenerator = inject ( _IdGenerator ) ;
194194 private _defaults = inject < MatFormFieldDefaultOptions > ( MAT_FORM_FIELD_DEFAULT_OPTIONS , {
195195 optional : true ,
196196 } ) ;
@@ -305,10 +305,10 @@ export class MatFormField
305305 _hasTextSuffix = false ;
306306
307307 // 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-' ) ;
309309
310310 // Unique id for the hint label.
311- readonly _hintLabelId = ` mat-mdc-hint-${ nextUniqueId ++ } ` ;
311+ readonly _hintLabelId = this . _idGenerator . getId ( ' mat-mdc-hint-' ) ;
312312
313313 /** State of the mat-hint and mat-error animations. */
314314 _subscriptAnimationState = '' ;
0 commit comments