Issue
I have an image element that is getting its path from an attribute I have on my angular object. However if this (imagePath) is empty I get a broken image. I would like to not render the image if the attribute is empty however I do not see a way to do this. Any ideas?
<img width="50px" src="/resources/img/products/{{current.manufacturerImage.imagePath}}">
Solution
You want to check out ngHide
directive.
So your code would look something like.
<img width="50px" ng-hide="current.manufacturerImage.imagePath == ''"
src="/resources/img/products/{{current.manufacturerImage.imagePath}}">
Alternatively, you could also try the suggestion by darkporter
<img width="50px" ng-show="current.manufacturerImage.imagePath"
src="/resources/img/products/{{current.manufacturerImage.imagePath}}">
You could also update this to check if the object is null or undefined then hide the element.
Answered By - Tim B James
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.