2

I'm having an issue with a simple thing I guess ...

I just need my span tag to have a class named store in a variable from my .ts file:

<span [ngClass]="{'flag-icon': true, 'my_property_in_TS': true}"></span>

I tried some things like this :

<span [ngClass]="{'flag-icon': true, ${lang.codeIcon}: true}"></span>

<span [ngClass]="{'flag-icon': true, lang.codeIcon: true}"></span>

I'm sure the answer is very simple... Does someone knows how to make it ?

0

2 Answers 2

4

You could try something like this -

<span [ngClass]="['flag-icon', lang.codeIcon]"></span>

For more ways -

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

1 Comment

Oh god I knew this was so simple .. Thank you @Pardeep !
3

To use the css class stored in lang.codeIcon, do like that:

<span [ngClass]="lang.codeIcon"></span>

For many classes, use an array:

<span [ngClass]="[lang.codeIcon, 'flag-icon']"></span>

For conditionnal, use braces:

<span [ngClass]="{'flag-icon': booleanVar, lang.codeIcon: !booleanVar}"></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.