Reputation: 439
I have an API call which returns back a number. If the number is positive show a green a image and if a button is negative show red I want a red image to show.
If I try this the image loops multiple time instead of a single time, How can I achieve this?
This is what I have
<td class="warning" [ngStyle]="{'background-image' : (reports.response_rate_7day_change > 0) ? getIncrease(): getDecrease() }"></td>
My functions to fetch the images from local storage
getIncrease()
{
return "url('assets/images/increase.png')";
}
getDecrease()
{
return "url('assets/images/decrease.png')";
}
when I run the code and the value returned is negative it show the image below, am not sure what am doing wrong
Upvotes: 0
Views: 657
Reputation: 3128
I think it has nothing to do with angular but your CSS try this:
<td class="warning" [ngStyle]="{'background-image' : (reports.response_rate_7day_change > 0) ? getIncrease(): getDecrease() }"
style="background-repeat: no-repeat"></td>
Upvotes: 2