Home > Software engineering >  How to set a material icon using strings?
How to set a material icon using strings?

Time:03-30

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?

CodePudding user response:

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.

  • Related