Search code examples
angulargoogle-material-icons

How to set a material icon using strings?


So I have to modify a mat card to include custom text and one of 3 icons (info, warning and danger, depending on the case). I have this in the html file:

<mat-card>
    <mat-icon aria-hidden="false" aria-label="info icon" *ngFor="let icon">{{icon}}</mat-icon>
</mat-card>

and in the .ts file I don't know how to set the card to a specific icon, as strings won't work. Any ideas how I could do that? How do I assign a specific icon?


Solution

  • I can see you have an unfinished *ngFor statement. It should be

    *ngFor="let icon of someList"
    

    Or maybe you wanted to do *ngIf="icon" Passing the string is probably fine.