[英]angular ng-show/hide depends on img src url
如何在永远不会为空的src url上显示/隐藏图像? 我尝试了ng-show =“ ImageUrl!==''/ null”,但是那是行不通的,因为始终存在URL,img src来自服务器端。
<img data-ng-src="{{ImageUrl}}" id="profile-picture_image" data-ng-show="ImageUrl" alt="Candidate profile photo" class="img-responsive img-rounded">
<img src="//@@websiteHost/Content/img/no-photo.png" alt="Candidate without profile photo" data-ng-show="!ImageUrl" class="img-responsive img-rounded">
请尝试以下操作:
html:
ng-show="isImageAvailable(this)"
控制器:
$scope.isImageAvailable = function(imageobj) {
var imagename = imageobj.replace(/^.*[\\\/]/, '');
return !(imagename == "no-photo.png");
}
或者类似从图像路径分解图像名称的方法:
var src = $('img').attr('src').split('/');
var file = src[src.length - 1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.