1

I have these two images

<img ng-show="cat1.PictureURIs[0].URI" src="{{cat1.PictureURIs[0].URI}}" />
<img ng-hide="cat1.PictureURIs[0].URI" src="/assets/img/placeholder.png">

Problem: If {{cat1.PictureURIs[0].URI}} not empty display first image else display second image. I use ng-show, ng-hide but not working.

Not working means: where {{cat1.PictureURIs[0].URI}} is not empty its also display second image, and where is {{cat1.PictureURIs[0].URI}} empty at that place its also displaying second image, but when I remove ng-show it display first image correctly.

3
  • Did you try using ng-if? Commented Jan 5, 2016 at 7:36
  • 1
    What is not working ? It is working here: plnkr.co/edit/70Rhng29h1LHIoYie5gT?p=preview Commented Jan 5, 2016 at 7:38
  • Did you check the example mentioned in the comments ? Commented Jan 5, 2016 at 7:41

3 Answers 3

1

Please update your code as follows:

<img ng-show="cat1.PictureURIs[0].URI != ''" src="{{cat1.PictureURIs[0].URI}}" />
<img ng-hide="cat1.PictureURIs[0].URI != ''" src="/assets/img/placeholder.png">

Give it a try.

Hope it works.!

Sign up to request clarification or add additional context in comments.

Comments

1

Something like,

<img ng-src="{{cat1.PictureURIs[0].URI? cat1.PictureURIs[0].URI : ('/assets/img/placeholder.png')}}"/>

It will help to achieve.

Comments

1

<img ng-src="{{cat1.PictureURIs[0].URI || '/assets/img/placeholder.png'}}" />

1 Comment

While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. For example, it's not immediately obvious what the difference is in your answer. You might want to explain ng-src.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.