Skip to content

Instantly share code, notes, and snippets.

Last active Jun 11, 2021
What would you like to do?
Font Awesome directive for Angular.js 1.x
import angular from 'angular';
import fontawesome from '@fortawesome/fontawesome-svg-core';
import {faPrint} from '@fortawesome/free-solid-svg-icons/faPrint';
import {faSearch} from '@fortawesome/free-solid-svg-icons/faSearch';
fontawesome.library.add(faPrint, faSearch);
function directive(): ng.IDirective {
return {
restrict: 'E',
link(_scope: ng.IScope, elem: JQLite, attrs: ng.IAttributes) {
const prefix = 'fas' as fontawesome.IconPrefix;
const iconName = attrs.fas as fontawesome.IconName;
const icon: fontawesome.Icon = fontawesome.icon({prefix, iconName});
if (!icon) {
console.warn(`No icon found for `, iconName);
// Usage: <font-awesome fas="print"></font-awesome>
export default angular.module('ngFontAwesome', []).directive({fontAwesome: directive});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment