angularjsangularjs-ng-show

ng-src with ng-show not working


I have appended /File/ in ng-src which calls my Image source from database through Id. How to use use ng-showcondition?

This is my code :

<img ng-src="/File/{{review.ProfileImage}}" class="media-object img-circle">

Anyone have a clue about this ?


Solution

  • You should not use interpolation inside ngShow directive. Just use a simple condition to check your review.ProfileImage field:

    <img ng-src="/File/{{review.ProfileImage}}" ng-show="review.ProfileImage" class="media-object img-circle"/>
    

    For your case I would recommend using ngIf instead of ngShow (in this case img will be removed from the DOM and you will not hit your back-end with image source request).