9
9
import { AriaDescriber , InteractivityChecker } from '@angular/cdk/a11y' ;
10
10
import { DOCUMENT } from '@angular/common' ;
11
11
import {
12
- ApplicationRef ,
13
12
booleanAttribute ,
14
13
ChangeDetectionStrategy ,
15
14
Component ,
16
- createComponent ,
17
15
Directive ,
18
16
ElementRef ,
19
- EnvironmentInjector ,
20
17
inject ,
21
18
Inject ,
22
19
Input ,
@@ -29,6 +26,7 @@ import {
29
26
ANIMATION_MODULE_TYPE ,
30
27
} from '@angular/core' ;
31
28
import { ThemePalette } from '@angular/material/core' ;
29
+ import { _CdkPrivateStyleLoader } from '@angular/cdk/private' ;
32
30
33
31
let nextId = 0 ;
34
32
@@ -48,9 +46,6 @@ export type MatBadgeSize = 'small' | 'medium' | 'large';
48
46
49
47
const BADGE_CONTENT_CLASS = 'mat-badge-content' ;
50
48
51
- /** Keeps track of the apps currently containing badges. */
52
- const badgeApps = new Set < ApplicationRef > ( ) ;
53
-
54
49
/**
55
50
* Component used to load the structural styles of the badge.
56
51
* @docs -private
@@ -162,36 +157,20 @@ export class MatBadge implements OnInit, OnDestroy {
162
157
private _renderer : Renderer2 ,
163
158
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) private _animationMode ?: string ,
164
159
) {
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 ) ;
181
162
182
163
if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
183
164
const nativeElement = _elementRef . nativeElement ;
184
165
if ( nativeElement . nodeType !== nativeElement . ELEMENT_NODE ) {
185
166
throw Error ( 'matBadge must be attached to an element node.' ) ;
186
167
}
187
168
188
- const matIconTagName : string = 'mat-icon' ;
189
-
190
169
// Heads-up for developers to avoid putting matBadge on <mat-icon>
191
170
// as it is aria-hidden by default docs mention this at:
192
171
// https://material.angular.io/components/badge/overview#accessibility
193
172
if (
194
- nativeElement . tagName . toLowerCase ( ) === matIconTagName &&
173
+ nativeElement . tagName . toLowerCase ( ) === 'mat-icon' &&
195
174
nativeElement . getAttribute ( 'aria-hidden' ) === 'true'
196
175
) {
197
176
console . warn (
0 commit comments