1

I am trying to make this property binding to work. I want to use ternary operator where conditions are interpolated strings. HTML is compiling, but the element is not showing.

<si-icon [icon]="item.isSelected ? 'element-face-{{item.faceColor}}-filled' : 'element-face-{{item.faceColor}}'"></si-icon>

Can someone point me what I am doing wrong here? Thank you!

1 Answer 1

2

Solution 1: In HTML

<si-icon [icon]="
    item.isSelected 
    ? 'element-face-' + item.faceColor + '-filled' 
    : 'element-face-' + item.faceColor">
</si-icon>

Solution 2: Get style name from component.

getIconStyle(isSelected: boolean, faceColor: string): string {
  return isSelected
    ? `element-face-${faceColor}-filled`
    : `element-face-${faceColor}`;
}
<si-icon [icon]="getIconStyle(item.isSelected, item.faceColor)">
</si-icon>

Sample Stackblitz Example

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.