I need a buton to display an image


#1

I am developing a mobile application With ionic 2 w I need a buton to display an image I need a button that allows to display a photo


#2

What do you mean by need a button to display image? I did not understand your question.


#3

That is to say when clicking on the buton the photo is displayed


#4

Seriously what do you even mean…

That is to say when clicking on the buton the photo is displayed

<button ion-button>when clicking on the buton the photo is displayed</button>


#5

yes , exactly !!!:!!


#6

In your class TS : page.ts add

...
// variable
private isDisplayImage: boolean = false;
...

// function
displayImage() {
   this.isDisplayImage = true;
}
...

and in your template.html

...
<img *ngIf="isDisplayImage" src="../assets/img/image.png" />
...
<button ion-button (click)="displayImage()">Display my image</button>
...

i wish that will be helpful


#7

thank you !
This code allows to display image but not to hide


#8

So you want the toggle button (Display/hide),
change the code of function like below

...
// function
displayImage() {
   this.isDisplayImage = !this.isDisplayImage;
}
...

#9

thank you yajuve !!! :slight_smile: