show the image based on a condition

Related searches

I want the image tag to show the image depending on a condition.

I tried the below code but it is not showing me the image

<img src="{{row.image}}!=null?'data:image/jpeg;base64,{{row.image}}':'./assets/img/quill1.png'">

Can someone tell what is that i am doing wrong.

Use *ngIf to conditionally show elements

<img *ngIf="row.image" [attr.src]="'data:image/jpeg;base64,' + row.image" />
<img *ngIf="!row.image" src="./assets/img/quill1.png" />


And you would ideally build the full base64 src string in your ts

Edit 2:

Example of conditional logic in attributes:

This is not my recommended approach, just an example

Display image based on condition., Hello, I'm fairly new to Spotfire and my apologies if this sounds stupid. I have a calculated field(%), that I want to use for passing custom images. Here Mudassar Ahmed Khan has explained with an example, how to display Image based on condition in GridView in ASP.Net using C# and VB.Net. The ImageUrl property of the Image control is set with an Inline Expression which compares the value of the column and based on the value, the respective Image URL is returned which is used to conditionally display the Image in GridView.

So you can split this into two elements:

<img *ngIf="row.image" [src]="'data:image/jpeg;base64,' + row.image" />
<img *ngIf="!row.image" src="./assets/img/quill1.png" />

or you can bind the result to a get function in your .ts file:


<img [src]="getImage"/>


get getImage() {
       return  this.row.image!=null?'data:image/jpeg;base64'+this.row.image:'./assets/img/quill1.png'

if the condition is true it has to display an image, now it is returning success and failed depending up on the condition.inplace of that i want two different images. Posted 25-May-12 20:29pm. Hence depending on the choice user has made based on the 2 questions, the different affiliate image will be shown. Hence, the end image will be as displayed: Image A -> if user has chosen "NO" and "0" Image B -> if user has chosen "YES" and "1" to "5"

You can try this.

Sometimes browser does not support the untrusted URL that is the reason you should use bypassSecurityTrustUrl due to security issues. You can see the documentation


import { DomSanitizer } from '@angular/platform-browser'; 

constructor(private xss: DomSanitizer) {}

safeURL(url: string): any {
    return this.xss.bypassSecurityTrustUrl(url);


<img [src]="row.image?safeURL('data:image/jpeg;base64,'+row.image):'/assets/img/quill1.png'"  alt="Avatar">   


<img [src]="safeURL('data:image/jpeg;base64,'+row.image)" onError="this.src='/assets/img/quill1.png'" alt="Avatar">   


<img *ngIf="row.image; else noAvatar;" [src]="safeURL('data:image/jpeg;base64,'+row.image)" alt="Avatar"/> 
<ng-template #noAvatar>
  <img [src]="'./assets/img/quill1.png'" alt="No Avatar">

Show images conditionally - Microsoft Tech Community, I would like to show some images in my Excel spreadsheet only when certain conditions are valid. Display image based on condition.xlsx. I want to show an image instead of text according to the data coming in the response of an API. If true - access symbol, If false - deny symbol should be shown. I tried but I am getting the link in the display not the image.

Solved: display image when a condition is met, Now I want to add a condition to the displaying of these images. When there's an ' X' in excel in a column, then the image needs to be displayed� Insert an Image connected to related image field. Set: Visible: If(Flammable.Text = "X", true, false) 1. Use Visible for the Image (because you use to toggle Show or No Show) 2. When using any Text Field Name, please use FielsName.Text. Hope this helps. TQ

display images based on condition, display images based on condition. Posted on December 12, 2008 at 3:14am. 0. HI,. i have a requirement to show the image/logo on the report. If i get store� Take two image buttons and give the image url's to those image buttons and write the code in page load as imagebutton1.visible= false; imagebutton2.visible= false; And in If condition you should write the code as

yes the webpage is free of errors but not getting the required image in specific location based on the if condition. i wanted to show you my ui page, here there is no option to copy the page

  • this logic should be wraped inside ts file not HTML! src tag is responsible to display the image either it should base64 or physical paht
  • I saw few examples where it is in html file
  • yes and it will work! but it will not easy to maintain and keep the code clean!
  • i have seen few examples where we can do in this way so wanted to check if that is possible
  • It is possible to use conditional logic, but I wouldn't say it's better. Example of conditional image url:
  • What you are saying is ternary operator and using that on html.
  • @Mridul not particularly nice, but is possible
  • @KurtHamilton, i know both the ways just saying what he's trying to refer.