Last active
June 11, 2021 05:25
-
-
Save simon04/adb1c609197b34acae5ba7d9a28f8f85 to your computer and use it in GitHub Desktop.
Font Awesome directive for Angular.js 1.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
return; | |
} | |
elem[0].append(icon.node[0]); | |
} | |
}; | |
} | |
// 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