In my current project, I have a requirement to display different images based on certain conditions. For example, if condition1 is met, I need to show image1, and so on for other conditions. To achieve this, I am currently using the ng-if
directive in my code like below:
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 form-col-pad customization-grid-data text-left"
ng-if="data.severity==3">
<img src="App/images/Icons/alarm-high.png">
</div>
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 form-col-pad customization-grid-data text-left"
ng-if="data.severity==2">
<img src="App/images/Icons/alarm-medium.png">
</div>
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 form-col-pad customization-grid-data text-left"
ng-if="data.severity==1">
<img src="App/images/Icons/alarm-low.png">
</div>
Although I only need to display one image at a time, I find myself repeating similar lines of code multiple times. Is there a way to optimize this using the ng-class
directive instead?