Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular2-svg-icons

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular2-svg-icons

Easily use icons in your Angular app with this component. It uses the `` element to duplicate SVG's without manipulating the DOM (the browser does all the work).

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Svg Icons

Easily use icons in your Angular app with this component. It uses the <use> element to duplicate SVG's without manipulating the DOM (the browser does all the work).

Install

$ npm install angular2-svg-icons --save

Then add it to the modules that require it:

import { IconModule } from 'angular2-svg-icons';

@NgModule({
  imports: [IconModule]
})
export class SomeModule {}

Use

<icon i="search"></icon>

The i attribute is the name (id) of the icon. The above code generates the following:

<svg class="icon"
     x="0" y="0"
     xmlns="http://www.w3.org/2000/svg"
     width="24px"
     height="24px"
     preserveAspectRatio="xMidYMin">
    <use xlink:href="baseUrl/#search" />
</svg>

Symbol Requirement

You must add all your symbols to your page prior to using this component. For example, you can create a svg-symbols.ts file that has all your symbols with the appropriate id as the name:

export const svgSymbols = `
<svg style="display: none">
    <symbol id="search" d="path-stuff"></symbol>
</svg>`;

Then add this to your application. For example, you can add it to your root component:

import { Component } from '@angular/core';
import { svgSymbols } from './components/icons/svg-symbols';

@Component({
  selector: 'app',
  template: `
${svgSymbols}
<rest-of-your-app></rest-of-your-app>`,
})
export class RootComponent { }

NOTE: It's recommended to hide the <svg> or else the entire sheet will be displayed when added to your app.

Easy svg to symbol creation

build-svg-sheet

I built a Gulp task that takes in an icon json file and then produces an svg-symbols.ts file for you. The repo houses all the svg icons, so all you have to do is specify the list of icons you want in your json file: ["search","home","person"].

This is pretty specific to my needs (and uses material icons), but you can fork it to create your own.

Styling

I purposefully left out styles -- the generated icons have an icon class so you can style them however you want. Just be aware of the limitations of the <use> element (A guide to SVG elements)

// example of changing color and size
// remember to style the <icon> element as well
icon {
    width: 24px;
    height: 24px;
    display: inline-block;

    svg {
        fill: #404040;
        width: 24px;
        height: 24px;
    }
}

FAQs

Package last updated on 28 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc