Close
Angular React Web Components Blazor Angular
Open Source

Angular Icon Service Overview

The Ignite UI for Angular Icon Service allows developers to add new icons from various sources to their UIs.

Introduction

The Ignite UI for Angular Icon Service provides several methods that allow users to create and manage icon families.

The icon service can be imported directly from the Ignite UI for Angular package.

import { IgxIconComponent } from 'igniteui-angular/icon';
import { IgxIconService } from 'igniteui-angular/core';

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [ IgxIconComponent ]
})
export class AppComponent implements OnInit {
    constructor(public iconService: IgxIconService) {}
}

Adding Icon Families

By default the Icon Service sets its default family to material.

Adding new families of icons is done using the setFamily method of the icon service. It creates an family entry with some metadata that instructs the igx-icon component about the icon(s) it should render.

Let’s use a practical example to explain how the setFamily method works:

/** 
* The icon service associates a given family name (provided by the user) 
* with a specific CSS class (as documented in the providing icon font) 
* and corresponding icon name (documented in the icon font).
* NOTE: Material is already the default family.
*/ 
iconService.setFamily('material', { className: 'material-icons', type: 'liga' });
iconService.setFamily('fa-solid', { className: 'fas', type: 'font', prefix: 'fa' });

The example above creates two icon families: ‘material’ and ‘fa-solid’. Their types are different, the material family is registered as liga, while the fa-solid family is registered as font. The difference between the two is how the igx-icon component would go about rendering them. Typically, Font Awesome uses class names to specify code points to a font family, hence why we set its type to font. Anytime we have to rely on code points to render icons, we should set the type to font. The Material Icons family is still a font family, however, the standard way to display an icon is to provide a ligature name, instead of a class name pointing to a specific code point. For that reason, we need to set the type to liga. There’s a third family type - svg, it is reserved for icon families that will be comprised of SVGs that are registered through the Icon Service.

Having registered the two font families above, we can now consume their icons in a standardized way via the igx-icon component:

<igx-icon family="material" name="home"></igx-icon>
<igx-icon family="fa-solid" name="car"></igx-icon>

To render icons from the default material family with igx-icon, add the following link to your index.html: <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

You might have noticed that for the material family we use the ligature name as name, while in the case of the fa-solid family we specify the className for name, which is fa-car but drop the fa- prefix as it has been specified when we registered the icon family in the previous step.

Adding SVG Icons

The Ignite UI for Angular Icon Service allows us to associate SVG images with families and give them names so that they can be included via the igx-icon component in the same way as font-based icons. The SVGs should be resolved via either strings or via absolute URI to the SVG asset.

// Add a new 'material' icon called 'my-icon' from an SVG file
iconService.addSvgIcon('my-icon', 'my-icon.svg', 'material');

// Add a new 'fa-solid' icon called 'my-icon' from string 
iconService.addSvgIconFromText('my-icon', '<svg>...</svg>', 'fa-solid');

Later in markup:

<igx-icon family="material" name="my-icon"></igx-icon>
<igx-icon family="fa-solid" name="my-icon"></igx-icon>

Note that we are adding custom SVG icons to families of type liga and font. This is possible because the addSvgIcon and addSvgIconFromText methods register the icons as svg type implicitly, allowing the igx-icon component to correctly render the SVG.

Meta Families

The Ignite UI for Angular Icon Service allows us to create pseudo family maps that combine icons added via either setting a family of font icons or adding SVGs under a common umbrella so that it’s easier to reference them.

// The `setIconRef` sets an icon reference in the icon map,
// assuming material and fa-solid have been added as families,
iconService.setIconRef('home', 'my-family', { family: 'material', name: 'home' });
iconService.setIconRef('home-alt', 'my-family', { family: 'fa-solid', name: 'home' });
iconService.setIconRef('car', 'my-family', { family: 'fa-solid', name: 'car' });

Later in markup:

<igx-icon family="my-family" name="home"></igx-icon>
<igx-icon family="my-family" name="home-alt"></igx-icon>
<igx-icon family="my-family" name="car"></igx-icon>

Icon Retrieval

It is possible to get an icon for a given family and icon name in order to read the original icon type, name, family, and className.

const { family, className, name, type } = iconService.getIcon('my-family', 'car');

console.log(family); // -> 'fa-solid'
console.log(className); // -> 'fas'
console.log(name); // -> 'fa-car'
console.log(type); // -> 'font'

Internal Usage

Starting with version 18.1.0 of Ignite UI for Angular, we added a new setFamily method that allows us to create new families of icons in the Icon Service and associate them with CSS classes, types, and even prefixes. Additionally, icons used internally are now all declared by reference in a new default family with aliased names (see table bellow).

AliasTarget IconTarget Family
addaddmaterial
add_childadd-childimx-icons
add_rowadd-rowimx-icons
arrow_backarrow_backmaterial
arrow_drop_downarrow_drop_upmaterial
arrow_forwardarrow_forwardmaterial
arrow_nextchevron_rightmaterial
arrow_prevchevron_leftmaterial
case_sensitivecase-sensitiveimx-icons
carousel_nextarrow_forwardmaterial
carousel_prevarrow_backmaterial
chevron_leftchevron_leftmaterial
chevron_rightchevron_rightmaterial
clockaccess_timematerial
closeclosematerial
collapseexpand_lessmaterial
confirmcheckmaterial
date_rangedate_rangematerial
deletedeletematerial
drag_indicatordrag_indicatormaterial
editeditmaterial
errorerrormaterial
expandexpand_morematerial
expand_moreexpand_morematerial
file_downloadfile_downloadmaterial
filter_allselect-allimx-icons
filter_beforeis-beforeimx-icons
filter_containscontainsimx-icons
filter_does_not_containdoes-not-containimx-icons
filter_emptyis-emptyimx-icons
filter_equalequalsimx-icons
filter_falseis-falseimx-icons
filter_greater_thangreater-thanimx-icons
filter_greater_than_or_equalgreater-than-or-equalimx-icons
filter_inis-inimx-icons
filter_last_monthlast-monthimx-icons
filter_last_yearlast-yearimx-icons
filter_less_thanless-thanimx-icons
filter_less_than_or_equalless-than-or-equalimx-icons
filter_next_monthnext-monthimx-icons
filter_next_yearnext-yearimx-icons
filter_not_emptynot-emptyimx-icons
filter_not_equalnot-equalimx-icons
filter_not_nullis-not-nullimx-icons
filter_nullis-nullimx-icons
filter_starts_withstarts-withimx-icons
filter_this_monththis-monthimx-icons
filter_this_yearthis-yearimx-icons
filter_todaytodayimx-icons
filter_trueis-trueimx-icons
filter_yesterdayyesterdayimx-icons
first_pagefirst_pagematerial
group_workgroup_workmaterial
hidevisibility_offmaterial
import_exportimport_exportmaterial
input_collapsearrow_drop_upmaterial
input_clearclearmaterial
input_expandarrow_drop_downmaterial
jump_downjump-downimx-icons
jump_upjump-upimx-icons
last_pagelast_pagematerial
more_vertmore_vertmaterial
nextnavigate_nextmaterial
pinpin-leftimx-icons
prevnavigate_beforematerial
refreshrefreshmaterial
removecancelmaterial
searchsearchmaterial
selecteddonematerial
showvisibilitymaterial
sort_ascarrow_upwardmaterial
sort_descarrow_downwardmaterial
functionsfunctionsmaterial
table_rowstable_rowsmaterial
todaycalendar_todaymaterial
tree_collapseexpand_morematerial
tree_expandchevron_rightmaterial
unfold_lessunfold_lessmaterial
unfold_moreunfold_morematerial
unpinunpin-leftimx-icons
view_columnview_columnmaterial

To take advantage of changing the internal icons by reference, as opposed by to creating custom templates, you can do the following to replace the expand/collapse icons in the combo and select components:

iconService.setIconRef('input_expand', 'default', {
    name: 'arrow_downward',
    family: 'material',
});

iconService.setIconRef('input_collapse', 'default', {
    name: 'arrow_upward',
    family: 'material',
});

This will set the expand and collapse icons to the arrow_downward and arrow_upward ligatures, respectively, from the material font family for all combo and select components.

Here’s a breakdown of all icons as used by each component:

Action Strip

IconDescription
add_childUsed by the popup menu.
add_rowUsed by the popup menu.
more_vertUsed by the popup menu.

Calendar

IconDescription
arrow_prevUsed by the header for navigating between months/years.
arrow_nextUsed by the header for navigating between months/years.
IconDescription
carousel_prevUsed for navigating between slides.
carousel_nextUsed for navigating between slides.

Chip

IconDescription
selectedUsed to indicate that a chip is selected.
removeUsed for the remove button.

Combo (incl. Simple Combo)

IconDescription
case_sensitiveUsed to indicate and toggle case-sensitive filtering.
input_clearUsed for the clear button.
input_expandUsed for the toggle button when the combo menu is collapsed.
input_collapseUsed for the toggle button when the combo menu is expanded.

Date Picker

IconDescription
todayUsed for the toggle button that triggers the picker.
input_clearUsed for the clear button.

Date Range Picker

IconDescription
date_rangeUsed for the toggle button that triggers the picker.

Expansion Panel

IconDescription
expandUsed for the toggle button that triggers the expanded state.
collapseUsed for the toggle button that triggers the collapsed state.

Grid

IconDescription
addUsed in excel-filter menu to add filter entry.
arrow_backUsed in various UI elements for moving a column backwards.
arrow_drop_downUsed in various buttons to indicate toggleable menus.
arrow_forwardUsed in various UI elements for moving a column forwards.
cancelUsed in various UI elements for canceling operations.
chevron_rightUsed to indicate expandable menus, like in the excel style filtering.
closeUsed to close an expanded menu.
confirmUsed to confirm an operation.
drag_indicatorUsed to show a handle to indicate an item can be dragged.
errorUsed in editable cells to indicate erroneous data input.
expand_moreUsed by the excel filtering menu to indicate the addition of more filters.
file_downloadUsed by the excel filter exporter.
filter_*Used for various filtering operands.
group_workUsed by the group-by drop area.
hideUsed by various UI elements for hiding columns.
import_exportUsed by the pivot data selector for moving.
input_clearUsed by input fields for clearing input data.
nextUsed by the filtering row menu to navigate between chips.
pinUsed by various UI elements for column pinning.
prevUsed by the filtering row menu to navigate between chips.
removeUsed by various UI elements as a removal indicator.
refreshUsed by the filtering row menu to reload the filters.
selectedUsed by various UI elements to indicated active selection.
showUsed by various UI elements for showing columns.
sort_ascUsed by various UI elements to indicate sorting direction.
sort_descUsed by various UI elements to indicate sorting direction.
functionsUsed by the pivot grid and data selectors.
table_rowsUsed by the pivot grid data selector.
tree_collapseUsed by tree-like structure to show less details.
tree_expandUsed by tree-like structure to show more details.
unpinUsed by various UI elements for column pinning.
unfold_lessUsed by the hierarchical grid to collapse all rows.
unfold_moreUsed by the hierarchical grid to expand all rows.
view_columnUsed by the pivot data selector.

Input Group

IconDescription
input_clearUsed for the clear button.

Paginator

IconDescription
first_pageUsed by the button used for navigating to the first page.
last_pageUsed by the button used for navigating to the last page.
prevUsed by the button used for navigating to the previous page.
nextUsed by the button used for navigating to the next page.

Query Builder

IconDescription
addUsed by the button for adding new filter entries.
closeUsed by the button that closes the contextual menu.
editUsed by the button for editing filter entries.
confirmUsed by the button to confirm adding new filter entries.
ungroupUsed by the button to ungroup filter entries.
deleteUsed by the button to delete filter entries.
filter_*Used for various filtering operands.

Select

IconDescription
input_expandUsed for the toggle button when the select menu is collapsed.
input_collapseUsed for the toggle button when the select menu is expanded.

Tabs

IconDescription
prevUsed by the button used for navigating to the previous tab.
nextUsed by the button used for navigating to the next tab.

Time Picker

IconDescription
clockUsed for the toggle button that triggers the picker.

Tree

IconDescription
tree_expandUsed for the toggle button that triggers the picker.
tree_collapseUsed for the toggle button that triggers the picker.

API

Here’s a quick summary of all methods available via the Ignite UI for Angular Icon Service.

Add Family

setFamily(name: string, meta: IconFamilyMeta): IgxIconService;

Icon References

Set ONLY if NOT already present the icon map:

addIconRef(name: string, family: string, icon: IconMeta): void;

Set an Icon reference in the icon map (overridden if already present):

setIconRef(name: string, family: string, icon: IconMeta): void;

Get and Icon reference

getIconRef(family: string, name: string): IconReference;

SVG Icons

From URI:

addSvgIcon(name: string, url: string, family: string, stripMeta = false): void;

From string:

addSvgIconFromText(name: string, iconText: string, family: string, stripMeta = false): void;

API References

Additional Resources


Our community is active and always welcoming to new ideas.