[英]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.