peters313
peters313

Reputation: 59

ng-if not working with ng-src

I'm attempting to use either an icon or an image, depending on what exists within our content management system to display. for some reason when the page displays some of the images are showing with the ng-if (commented out) in the dev tools but it's not showing the image on the page like it should be.

Here is the binding utilizing:

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

and here is the front end:

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

what is causing the ng-if to pick up the image path but not display it?

Upvotes: 0

Views: 515

Answers (2)

you can try like this: ng-src="{{imgPath}}"

Upvotes: 0

Hadi
Hadi

Reputation: 17299

you can call function to set image in img tag.

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

and in controller check condition

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

 };

Upvotes: 1

Related Questions