Skip to content

Instantly share code, notes, and snippets.

@NBprojekt
Created October 10, 2019 11:23
Show Gist options
  • Save NBprojekt/01d22260630a694df35f0f6209dd6f64 to your computer and use it in GitHub Desktop.
Save NBprojekt/01d22260630a694df35f0f6209dd6f64 to your computer and use it in GitHub Desktop.
Use font awesome icons in mat badge
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