0

Having this template:

<li role="menu" class="drop-down">
  <a class="drop-down--toggle">
    <span class="flag-icon" [class]="_current.flag"//<-- don't work></span>
  </a>
  <ul class="drop-down--menu>
  ...
  </ul>
</li>

and this model:

export class LocaleModel {
  id: number;
  code: string;
  name: string;
  fileName: string;
  flag: string;// <-- could be "flag-icon-es" or "flag-icon-gb"

  constructor(id: number, code: string, name: string, fileName: string, flag: string) {}
  }

the desired end effect will be:

<li role="menu" class="drop-down">
  <a class="drop-down--toggle">
    <span class="flag-icon flag-icon-es"></span>
  </a>
  <ul class="drop-down--menu">
  ...
  </ul>
</li>

Is it possible to have part of the class added dynamically or should I save the whole class name like "flag-icon flag-icon-es" and add it whole?

1 Answer 1

3

Use ngClass as given below :

<span class="flag-icon" [ngClass]="[_current.flag]"></span>
Sign up to request clarification or add additional context in comments.

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.