components icon indicating copy to clipboard operation
components copied to clipboard

feat(MatIconRegistry): reactive signatures

Open aalbericio opened this issue 1 year ago • 1 comments
trafficstars

Feature Description

When I use MatIconRegistry, and I add an "iconSet" using "addSvgIconSet", I don't see any way of subscribing to what's internally doing: loading file -> generating an html/svg representation -> etc

And I don't know when all that computation has finished.

I'm using a little "hack" to subscribe to that workflow using:

matIconRegistry.getNamedSvgIcon(<name of icon I know it's in the iconSet>).subscribe(...)`

But that's kinda weak since I have to know the contents (what SVGs are included) in the iconSet.

I would like to have a robust API so that I can subscribe to that internal workflow and know when it has finished its calculations, something like:

matIconRegistry.addSvgIconSet(<icon_set_file>).subscribe(...)

Even more interesting, allow this registry to load multiple files at once:

matIconRegistry.addSvgIconSet([<icon_set_file_1>, <icon_set_file_2>...]).subscribe(...)

Use Case

Synchronize APP Icons configuration at bootstrap.

Thanks

aalbericio avatar Jul 16 '24 07:07 aalbericio

There aren't really any calculations going on. The icon just makes an HTTP request when trying to display an icon, it extracts the SVG text and it caches the result. Even if we added events, I suspect they wouldn't be particularly useful.

crisbeto avatar Jul 17 '24 07:07 crisbeto

Same issue, same use-case.

In our case, we don't have icon name, so we use the hack with empty string

	private loadSprite(path: string) {
		const safeUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(path);
		this.matIconRegistry.addSvgIconSet(safeUrl);
		return this.matIconRegistry.getNamedSvgIcon('').pipe(...)

I suspect they wouldn't be particularly useful

I obviously disagree as you can see

tomer953 avatar Jul 17 '25 11:07 tomer953

Same issue, same use-case.

In our case, we don't have icon name, so we use the hack with empty string

private loadSprite(path: string) { const safeUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(path); this.matIconRegistry.addSvgIconSet(safeUrl); return this.matIconRegistry.getNamedSvgIcon('').pipe(...)

I suspect they wouldn't be particularly useful

I obviously disagree as you can see

Just to clarify, the goal of this use case is to track whether the icons have successfully loaded. This allows us to display a loading screen in the meantime, preventing icons from suddenly popping in after the UI is already visible.

AlonMiz avatar Jul 17 '25 14:07 AlonMiz