Svg Sprites
A directive for rendering symbols of svg sprites. It is done with the use
element.
Import
Usage
In this example the symbol github
of the fontawesome svg sprite fa-brands
is rendered. A symbol is identified by a fragment
. Learn more about URLs.
Without NgxSvgSpriteFragment
:
With Directive Composition Api
In your project you can utilize the Directive Composition Api to create specific svg sprites.
In this example a fontawesome brands svg sprite is created.
Configuration
In order to render a symbol, sprites have to be provided.
The name
property can reference any arbitrary value, but should be unique, since you can register multiple different svg sprites.
The sprite
input of the NgxSvgSpriteFragment
should reference the name
property of a provided sprite.
Auto View Box
When a symbol of an svg sprite is rendered the viewBox
attribute or height
and width
should be set. The svg
element does not copy/use the viewBox
attribute of the symbol in the svg sprite, therefore the svg will have default dimensions of 300x150 px, which is probably not preferred.
Per default when an svg sprite is registered, the svg sprite is fetched with js in addition. NgxSvgSpriteFragment
will copy the viewBox
attribute of the symbol to its host.
This behavior can be disabled.
Disable via DI
Auto View Box is disabled for the svg sprite.
Disable via autoViewBoxDisabled
Input
Auto View Box is disabled for a svg
element, when the autoViewBoxDisabled
input is set to false
.
Disable via viewBox
Attribute
Auto View Box is disabled for a svg
element, when the viewBox
attribute already is defined.
Classes
When the classes
function is set, a list of classes will be added by the NgxSvgSpriteFragment
to its host.
Url
Per default when providing a sprite, the url
will return '${baseUrl}#${fragment}'
. This can be overwritten: