ionic3 - 如何使用 if else 语句来回切换图像?
解决方案
这是一个通过动作切换图像的示例组件:
组件的 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 在条件下隐藏!根据您的需要修改示例!
推荐阅读
- java - 动态 Web 项目 (Eclipse) 中的 java.lang.UnsupportedClassVersionError
- r - 在R中的多个特定单词之间提取一串单词
- android - 加密内容的文件共享
- laravel - 在查询中使用 groupBy() 时如何在刀片视图中显示 Laravel 关系数据
- python - 未能获得正整数
- cocoa - 光标奇怪的行为:重置为默认值
- json.net - SwaggerUI 5.0.0 忽略 JsonProperty 名称
- python - 在 Ubuntu 16.04 Python 3.7 中,这些要求无法为 Odoo 13 安装
- python - 如何使用 Python 将 Web 服务的非常大的 JSON 响应转换为 CSV?
- android - 如何在游戏结束屏幕上显示最终分数和高分?