66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { AriaDescriber , InteractivityChecker } from '@angular/cdk/a11y' ;
9+ import { _IdGenerator , AriaDescriber , InteractivityChecker } from '@angular/cdk/a11y' ;
1010import { DOCUMENT } from '@angular/common' ;
1111import {
1212 booleanAttribute ,
@@ -26,8 +26,6 @@ import {
2626import { ThemePalette } from '@angular/material/core' ;
2727import { _CdkPrivateStyleLoader , _VisuallyHiddenLoader } from '@angular/cdk/private' ;
2828
29- let nextId = 0 ;
30-
3129/** Allowed position options for matBadgePosition */
3230export type MatBadgePosition =
3331 | 'above after'
@@ -79,6 +77,7 @@ export class MatBadge implements OnInit, OnDestroy {
7977 private _ariaDescriber = inject ( AriaDescriber ) ;
8078 private _renderer = inject ( Renderer2 ) ;
8179 private _animationMode = inject ( ANIMATION_MODULE_TYPE , { optional : true } ) ;
80+ private _idGenerator = inject ( _IdGenerator ) ;
8281
8382 /**
8483 * Theme color of the badge. This API is supported in M2 themes only, it
@@ -135,9 +134,6 @@ export class MatBadge implements OnInit, OnDestroy {
135134 /** Whether the badge is hidden. */
136135 @Input ( { alias : 'matBadgeHidden' , transform : booleanAttribute } ) hidden : boolean ;
137136
138- /** Unique id for the badge */
139- _id : number = nextId ++ ;
140-
141137 /** Visible badge element. */
142138 private _badgeElement : HTMLElement | undefined ;
143139
@@ -236,7 +232,7 @@ export class MatBadge implements OnInit, OnDestroy {
236232 const badgeElement = this . _renderer . createElement ( 'span' ) ;
237233 const activeClass = 'mat-badge-active' ;
238234
239- badgeElement . setAttribute ( 'id' , ` mat-badge-content-${ this . _id } ` ) ;
235+ badgeElement . setAttribute ( 'id' , this . _idGenerator . getId ( ' mat-badge-content-' ) ) ;
240236
241237 // The badge is aria-hidden because we don't want it to appear in the page's navigation
242238 // flow. Instead, we use the badge to describe the decorated element with aria-describedby.
0 commit comments