angular ng显示/隐藏取决于img src url

angular ng-show/hide depends on img src url

本文关键字:img src url 取决于 隐藏 ng 显示 angular      更新时间:2023-09-26

如何在永远不会为空的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];