angular ng-show / hide取决于img src url

时间:2016-01-06 09:25:14

标签: javascript angularjs

如何在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">

1 个答案:

答案 0 :(得分:0)

尝试下面的内容:

html:

$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];

或类似于从图像路径中分解图像名称:

$(document).ready(function(){
    if($(".variable-list-wrapper").length){
      $("table.variable-list").css("color","blue");
    }
});