66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
10- import { DOCUMENT } from '@angular/common' ;
119import {
12- ApplicationRef ,
1310 ChangeDetectionStrategy ,
1411 Component ,
15- EnvironmentInjector ,
1612 Inject ,
1713 Injectable ,
1814 NgZone ,
1915 OnDestroy ,
2016 ViewEncapsulation ,
2117 WritableSignal ,
22- createComponent ,
2318 inject ,
2419 signal ,
2520} from '@angular/core' ;
21+ import { DOCUMENT } from '@angular/common' ;
22+ import { normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
23+ import { _CdkPrivateStyleLoader } from '@angular/cdk/private' ;
2624import { Observable , Observer , Subject , merge } from 'rxjs' ;
2725import type { DropListRef } from './drop-list-ref' ;
2826import type { DragRef } from './drag-ref' ;
@@ -33,9 +31,6 @@ const activeCapturingEventOptions = normalizePassiveListenerOptions({
3331 capture : true ,
3432} ) ;
3533
36- /** Keeps track of the apps currently containing drag items. */
37- const activeApps = new Set < ApplicationRef > ( ) ;
38-
3934/**
4035 * Component used to load the drag&drop reset styles.
4136 * @docs -private
@@ -59,8 +54,7 @@ export class _ResetsLoader {}
5954@Injectable ( { providedIn : 'root' } )
6055export class DragDropRegistry < _ = unknown , __ = unknown > implements OnDestroy {
6156 private _document : Document ;
62- private _appRef = inject ( ApplicationRef ) ;
63- private _environmentInjector = inject ( EnvironmentInjector ) ;
57+ private _styleLoader = inject ( _CdkPrivateStyleLoader ) ;
6458
6559 /** Registered drop container instances. */
6660 private _dropInstances = new Set < DropListRef > ( ) ;
@@ -169,7 +163,7 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy {
169163 return ;
170164 }
171165
172- this . _loadResets ( ) ;
166+ this . _styleLoader . load ( _ResetsLoader ) ;
173167 this . _activeDragInstances . update ( instances => [ ...instances , drag ] ) ;
174168
175169 if ( this . _activeDragInstances ( ) . length === 1 ) {
@@ -313,23 +307,4 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy {
313307
314308 this . _globalListeners . clear ( ) ;
315309 }
316-
317- // TODO(crisbeto): abstract this away into something reusable.
318- /** Loads the CSS resets needed for the module to work correctly. */
319- private _loadResets ( ) {
320- if ( ! activeApps . has ( this . _appRef ) ) {
321- activeApps . add ( this . _appRef ) ;
322-
323- const componentRef = createComponent ( _ResetsLoader , {
324- environmentInjector : this . _environmentInjector ,
325- } ) ;
326-
327- this . _appRef . onDestroy ( ( ) => {
328- activeApps . delete ( this . _appRef ) ;
329- if ( activeApps . size === 0 ) {
330- componentRef . destroy ( ) ;
331- }
332- } ) ;
333- }
334- }
335310}
0 commit comments