ng-如果不与ng-src一起工作

ng-if not working with ng-src

本文关键字:一起 工作 ng-src 如果不 ng-      更新时间:2023-09-26

我正在尝试使用图标或图像,具体取决于我们的内容管理系统中存在的内容。 出于某种原因,当页面显示时,某些图像在开发工具中以 ng-if(注释掉)显示,但它没有像应有的那样在页面上显示图像。

以下是使用

<% String iconClass = "icon-img-" + properties.get("iconClass" , "");
pageContext.setAttribute("iconClass", iconClass); %> 

这是前端:

<h3 class="header__heading beta"><span class="${iconClass} header__icon" aria-hidden="true"><img ng-if="${imgPath}" ng-src="${imgPath}"/></span> ${title}</h3>

是什么导致 NG-if 选取图像路径但不显示它?

你可以调用函数来设置img标签中的图像。

 <img ng-src="setImage(${imgPath})">

和控制器检查条件

 $scope.setImage = function(imgPath){
   if(imgPath.isAdvert)
     //
   else
    //
 };

你可以这样尝试: ng-src="{{imgPath}}"