【问题标题】:How can i implement a switching image back and forth using if else statement?如何使用 if else 语句来回切换图像?
【发布时间】:2019-10-08 20:05:29
【问题描述】:

大家好,我不想使用 if else 语句来回切换建筑布局图像和建筑设计图像,但我不知道如何实现它。我是这种类型脚本的新手,有人愿意分享答案吗?

感谢您的高级回答

【问题讨论】:

  • 你的意思是按按钮切换到另一个图像,然后按返回按钮切换回原始图像

标签: ionic3


【解决方案1】:

这是一个通过动作切换图像的示例组件:

组件的HTML:


<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;
 };

*ngIf 在条件下隐藏!根据您的需要修改示例!

【讨论】:

    猜你喜欢
    • 2013-01-07
    • 1970-01-01
    • 2019-04-09
    • 2010-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 2020-08-20
    相关资源
    最近更新 更多