GitHub

DaffStyleInjector

class

import { DaffStyleInjector } from '@daffodil/content'

Service for injecting style tags into the document head. Useful for dynamically generated styles that need to be cleaned up later. Memoizes styles to avoid duplicate style tags for the same CSS.

@Injectable()
class DaffStyleInjector {
  inject(css: string): HTMLStyleElement
  destroy(styleTag: HTMLStyleElement): void
  destroyAll(): void
}

() Methods

inject
HTMLStyleElement

Injects a style tag into the document head with the provided CSS. Returns the cached style element if the same CSS was already injected.

Parameters
Parametercss: string
Description

The CSS string to inject

destroy
void

Removes a specific style tag from the document and cache.

Parameters
ParameterstyleTag: HTMLStyleElement
Description

The style element to remove

destroyAll
void

Removes all injected style tags from the document and clears the cache.