Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <mat-icon> in innerHTML does not work

Tags:

angular

I am trying to display strings containing <mat-icon> from my component, and having problem rendering them. The regular HTML elements, like bold, show fine, but not the mat-icon, which only shows the name. Any idea how to do it?

component.cs

this.info = "Press <mat-icon>cloud_download</mat-icon> <b>Download</b> button."

component.html

<p innerHTML={{info}}>{{info}}</p>

Result

Press cloud_download Download

like image 605
Nightrain Avatar asked May 17 '19 06:05

Nightrain


2 Answers

You could try using a span with the material-icons class. Eg: <span class="material-icons">cloud_download</span>

As far as I recall it won't render exactly the same as a mat-icon but quite similar, and probably more suitable for embedding in text

like image 188
Michael Avatar answered Nov 11 '22 21:11

Michael


Change your code to this and try again :

<p innerHTML="{{info}}">{{info}}</p>

You should use either innerHTML="{{action.content}}" or [innerHTML]="action.content" but not [innerHTML]="{{action.content}}" or innerHTML={{action.content}}

like image 1
vsarunov Avatar answered Nov 11 '22 20:11

vsarunov