1

I would like to dynamically generate a class name for my element. For example, <span class=``icon icon-${route.title}``></span> (had to use double backticks here, but it should really be just one set of backticks.)

    <ul class="sidebar-list">
      <li *ngFor="let route of menuRoutes.items">
        <span class=`icon icon-${route.title}`></span>
        <a routerLink="/{{route.path}}" routerLinkActive="active">{{ 'menu.' + route.title | translate}}</a> 
      </li>
    </ul>

2 Answers 2

7

Try this:

<span class="icon icon-{{route.title}}"></span>
Sign up to request clarification or add additional context in comments.

Comments

2

You can also archive this by using a [ngClass] directive

<span [ngClass]="['icon', route.title]"></span>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.