99import { AriaDescriber , InteractivityChecker } from '@angular/cdk/a11y' ;
1010import { DOCUMENT } from '@angular/common' ;
1111import {
12- ApplicationRef ,
1312 booleanAttribute ,
1413 ChangeDetectionStrategy ,
1514 Component ,
16- createComponent ,
1715 Directive ,
1816 ElementRef ,
19- EnvironmentInjector ,
2017 inject ,
2118 Inject ,
2219 Input ,
@@ -29,6 +26,7 @@ import {
2926 ANIMATION_MODULE_TYPE ,
3027} from '@angular/core' ;
3128import { ThemePalette } from '@angular/material/core' ;
29+ import { _CdkPrivateStyleLoader } from '@angular/cdk/private' ;
3230
3331let nextId = 0 ;
3432
@@ -48,9 +46,6 @@ export type MatBadgeSize = 'small' | 'medium' | 'large';
4846
4947const BADGE_CONTENT_CLASS = 'mat-badge-content' ;
5048
51- /** Keeps track of the apps currently containing badges. */
52- const badgeApps = new Set < ApplicationRef > ( ) ;
53-
5449/**
5550 * Component used to load the structural styles of the badge.
5651 * @docs -private
@@ -162,36 +157,20 @@ export class MatBadge implements OnInit, OnDestroy {
162157 private _renderer : Renderer2 ,
163158 @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) private _animationMode ?: string ,
164159 ) {
165- const appRef = inject ( ApplicationRef ) ;
166-
167- if ( ! badgeApps . has ( appRef ) ) {
168- badgeApps . add ( appRef ) ;
169-
170- const componentRef = createComponent ( _MatBadgeStyleLoader , {
171- environmentInjector : inject ( EnvironmentInjector ) ,
172- } ) ;
173-
174- appRef . onDestroy ( ( ) => {
175- badgeApps . delete ( appRef ) ;
176- if ( badgeApps . size === 0 ) {
177- componentRef . destroy ( ) ;
178- }
179- } ) ;
180- }
160+ const styleLoader = inject ( _CdkPrivateStyleLoader ) ;
161+ styleLoader . load ( _MatBadgeStyleLoader ) ;
181162
182163 if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
183164 const nativeElement = _elementRef . nativeElement ;
184165 if ( nativeElement . nodeType !== nativeElement . ELEMENT_NODE ) {
185166 throw Error ( 'matBadge must be attached to an element node.' ) ;
186167 }
187168
188- const matIconTagName : string = 'mat-icon' ;
189-
190169 // Heads-up for developers to avoid putting matBadge on <mat-icon>
191170 // as it is aria-hidden by default docs mention this at:
192171 // https://material.angular.io/components/badge/overview#accessibility
193172 if (
194- nativeElement . tagName . toLowerCase ( ) === matIconTagName &&
173+ nativeElement . tagName . toLowerCase ( ) === 'mat-icon' &&
195174 nativeElement . getAttribute ( 'aria-hidden' ) === 'true'
196175 ) {
197176 console . warn (
0 commit comments