Created
October 10, 2019 11:23
-
-
Save NBprojekt/01d22260630a694df35f0f6209dd6f64 to your computer and use it in GitHub Desktop.
Use font awesome icons in mat badge
This file contains 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 { Directive, ElementRef, Input, OnInit } from '@angular/core'; | |
@Directive({ | |
selector: '[matBadgeIcon]' | |
}) | |
export class MatBadgeIconDirective implements OnInit{ | |
@Input() matBadgeIcon: string; | |
constructor(private el: ElementRef) {} | |
ngOnInit() { | |
if (!this.matBadgeIcon) return; | |
const badge = this.el.nativeElement.querySelector('.mat-badge-content'); | |
badge.style.display = 'flex'; | |
badge.style.alignItems = 'center'; | |
badge.style.justifyContent = 'center'; | |
badge.innerHTML = `<i class="${this.matBadgeIcon}"></i>`; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment