How can i implement a switching image back and forth using if else statement?

时光毁灭记忆、已成空白 提交于 2020-01-16 09:13:06

问题


Hi everyone i wan't to switch building layout image to building design image back and forth using if else statement but i don't know how to implement it. I'am new in this type script, anybody would love to share an answer?

Thank you for your answers in advanced


回答1:


here is an example-component to switch a image by a action:

HTML of component:


<ion-list>
      <ion-item *ngIf="showImage1">
          <img src="../assets/imgs/dots.gif" height="50px" width="50px" >
     </ion-item>
      <ion-item *ngIf="showImage2">
          <img src="../assets/imgs/dots.gif" height="50px" width="50px" >
     </ion-item>
</ion-list>
<ion-button (click)="DoHideImage1()"  expand="block" color="light">
  Image2
</ion-button>
<ion-button (click)="DoHideImage2()"  expand="block" color="light">
  Image1
</ion-button>

Typescript of component:
________________________________________

public showImage1: boolean;
public showImage2: boolean;

constructor() {
  this.showImage1 = true;
  this.showImage2 = false;
}

DoHideImage1(){  
      this.showImage1 = false;
      this.showImage2 = true;
 };
DoHideImage2(){  
      this.showImage1 = true;
      this.showImage2 = false;
 };

The *ngIf hides on condition ! Modify the example for your needs!



来源:https://stackoverflow.com/questions/58282058/how-can-i-implement-a-switching-image-back-and-forth-using-if-else-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!