0

In my .css file I have multiple classes representing my webpage's icon. Based on what I retrieve from my code I want to change the icon.

<ng-container *ngFor="let item of parameterStruct">
   <span class="m-menu__link-wrap">
     <i class="sidebar-icon HERE"></i>
       <span class="m-menu__link-text icon-padding sideBar-text"
          style="padding-left: 15px; font-size: 12px"> 
           {{ item.description |translate }}
        </span>
   </span>
</ng-container>

Where I wrote HERE (in the i element) I want to insert my .css class that is item.description + '-icon' (E.g. 'myClass-icon').

How can I do that?

3 Answers 3

2

You can use the NgClass directive. Something like:

<i class="sidebar-icon" [ngClass]="{'first-icon': item.description === 'first', 'second-icon': item.description === 'second'}"></i>

Sign up to request clarification or add additional context in comments.

1 Comment

That is what I was looking for. Thanks
0

Try this

<i class="sidebar-icon {{item.description}}-icon"></i>

Comments

0

To achieve expected result, use below option of using ngClass

<i class="sidebar-icon" [ngClass]="item.description?item.description + '-icon': ''"></i>

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.