简体   繁体   English

角度ng-show / hide取决于img src url

[英]angular ng-show/hide depends on img src url

How to do ng-show/hide an image base on the src url which is never going to be empty? 如何在永远不会为空的src url上显示/隐藏图像? I tried ng-show="ImageUrl!== ''/null" but that's not going to work because there url is always present, the img src is coming from the server side. 我尝试了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">

Try something below: 请尝试以下操作:

html : html:

ng-show="isImageAvailable(this)"

controller: 控制器:

$scope.isImageAvailable = function(imageobj) {
    var imagename = imageobj.replace(/^.*[\\\/]/, '');
    return !(imagename == "no-photo.png");
}

Or something like to explode the image name from image path: 或者类似从图像路径分解图像名称的方法:

var src = $('img').attr('src').split('/');
var file = src[src.length - 1];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM