* Loads a set of styles. * @param loader Component which will be instantiated to load the styles.
(loader: Type<unknown>)
| 44 | * @param loader Component which will be instantiated to load the styles. |
| 45 | */ |
| 46 | load(loader: Type<unknown>): void { |
| 47 | // Resolve the app ref lazily to avoid circular dependency errors if this is called too early. |
| 48 | const appRef = (this._appRef = this._appRef || this._injector.get(ApplicationRef)); |
| 49 | let data = appsWithLoaders.get(appRef); |
| 50 | |
| 51 | // If we haven't loaded for this app before, we have to initialize it. |
| 52 | if (!data) { |
| 53 | data = {loaders: new Set(), refs: []}; |
| 54 | appsWithLoaders.set(appRef, data); |
| 55 | |
| 56 | // When the app is destroyed, we need to clean up all the related loaders. |
| 57 | appRef.onDestroy(() => { |
| 58 | appsWithLoaders.get(appRef)?.refs.forEach(ref => ref.destroy()); |
| 59 | appsWithLoaders.delete(appRef); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | // If the loader hasn't been loaded before, we need to instatiate it. |
| 64 | if (!data.loaders.has(loader)) { |
| 65 | data.loaders.add(loader); |
| 66 | data.refs.push(createComponent(loader, {environmentInjector: this._environmentInjector})); |
| 67 | } |
| 68 | } |
| 69 | } |
no test coverage detected