MUHAMMAD
HUZAIFA
Using angular-svg-
icon
Date: Jan 30, 2025
Old Method: Using IMG Tag to display SVGs
Issue: Can’t change color of SVG
Solution By: Muhammad Huzaifa
Background
While adding SideNavbar Icons, I noticed that we’re using IMG tag to display SVG’s. One of
the main reason behind using SVGs is that, we can customize their color as per our need. But
if we use IMG tag to display SVG, we can’t change color.
In angular, there is no other way to display SVG’s from Internet or Public Directory by default.
We have to create SVG Icon registry to extract the code of SVG from Internet or Public
Directory, sanitize it from malicious code, and then add them as a component in our code.
Doing this manually takes a lot of time. So I found a library doing all of this, and saving our
time.
Usage
Steps:
Run npm i angular-svg-icon@18.0.2 (compatible with Angular v18)
In [Link], add this provider: [Link]()
Import SvgIconComponent in any component where you want to use SVGs.
Use them in html file of component