[英]Show hide in angularJS if not empty
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. 问题:如果{{cat1.PictureURIs[0].URI}}
不为空,则显示第一个图像,否则显示第二个图像。 I use ng-show
, ng-hide
but not working. 我使用ng-show
, ng-hide
但不工作。
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. 不工作意味着: {{cat1.PictureURIs[0].URI}}
不为空时它也显示第二个图像, {{cat1.PictureURIs[0].URI}}
在那个地方为空它还显示第二个图像,但是当我删除ng-show
它会正确显示第一张图像。
Something like, 就像是,
<img ng-src="{{cat1.PictureURIs[0].URI? cat1.PictureURIs[0].URI : ('/assets/img/placeholder.png')}}"/>
It will help to achieve. 这将有助于实现。
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.! 希望它有效。
<img ng-src="{{cat1.PictureURIs[0].URI || '/assets/img/placeholder.png'}}" />
\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.