I want to change img tag src based on a condition. I am using ternary operator right now; I want to ask is there a way to use ngSwitch instead (WITHOUT REPEATING the img tag). Here is my code:
<div>
<img height='26' width='22' [src]="
bank.bankName.includes('a') ? 'assets/images/a.png' :
bank.bankName.includes('b') ? 'assets/images/b.png' :
bank.bankName.includes('c') ? 'assets/images/c.png' :
bank.bankName.includes('d') ? 'assets/images/d.png' : ''
" />
</div>
Writing code in a chain of ternary operators is never really a good move, especially in HTML templates. The switch is fine and if you really want to avoid it, you can simply write this code in component.ts file and set an
public imageSrc = ''named peropty, compute the result and assign it.