Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass value dynamically to data-* attribute [Angular2] [duplicate]

I want to write a component, which basically display a different icon based on its input. The icon framework is expecting it in the following format:

  <span class="icon icon-generic" data-icon="B"></span>

So data-icon="B" describes basically which icon to display. I would like to pass this symbol dynamically. Something like:

  <span class="icon icon-generic" data-icon={{symbol}}></span>

But this seems not to work. :-/ Is there a way to do this without creating the html in my Component class and appending it to the html?

like image 454
tschaka1904 Avatar asked Mar 24 '17 12:03

tschaka1904


1 Answers

Use

 <span class="icon icon-generic" [attr.data-icon]='symbol'></span>
like image 89
Pardeep Jain Avatar answered Oct 13 '22 00:10

Pardeep Jain