Search code examples
angularjsng-hideangularjs-ng-show

Angular. How to hide data in the title attribute of the image if the object value is null?


I understand ng-show/ng-hide can be used but this case is a little different. This is my script below. Basically what I'm trying to do is hide the word "PEAK" if 'info.peak' value is empty in the title tag. DO I need to create two versions of this image tag? One with and without 'peak'? If show How would I do that also?

<img 
class="icon lazyloaded"  
data-ng-src="{{ info.image }}" 
alt="{{ info.title }}"  
title="Last Week: {{ info.lastweek}}  Move: {{ info.move }} Peak: {{ info.peak }}" 
width="100" 
height="100"> 

Solution

  • You can do this with the following:

    {{ info.peak ? 'Peak: ' + info.peak : '' }}
    

    in place of where you have Peak: {{ info.peak }}. So if info.peak does not exist/is null, it will simply append an empty string to the end.