I have this code in component.html
<div class="dashboard-table-item row"
*ngFor="let item of itemArray">
<span>{{item.value == 'user' ? 'student' : item.value | titlecase}}</span>
</div>
itemArray can have one of this values: admin | editor | user I want without modifying the itemArray output: user --> student and then titlecase it.
I know I could change 'student' for 'Student' and it works, but my question is why does pipe(| titlecase) not work with ternary operator(condition ? 'value1' : item.value) Value1
Try wrapping your ternary condition with parenthesis ()
. This worked for me:
<div class="dashboard-table-item row"
*ngFor="let item of itemArray">
<span>{{(item.value == 'user' ? 'student' : item.value ) | titlecase}}</span>
</div>