简体   繁体   English

如何使用 *ngIf 指令更改图像?

[英]How can I use *ngIf directive to change an image?

I'm developing an application with the technologies shown below.我正在使用下面显示的技术开发应用程序。 How can i use *ngIf directive to change an image with another one?如何使用 *ngIf 指令将图像更改为另一个图像? I will be more precise in explaining my intentions;我会更准确地解释我的意图; I've two images (male symbol ♂ and female symbol ♀), when I've 'gender == M' I have to display male symbol, instead when I've 'gender == F' I have to display feminin symbol.我有两个图像(男性符号 ♂ 和女性符号 ♀),当我有“性别 == M”时,我必须显示男性符号,而当我有“性别 == F”时,我必须显示女性符号。 Thanks to everyone!谢谢大家!

Technologies that I currently use:我目前使用的技术:

  • Ionic 4.10.2离子 4.10.2
  • Angular 6角 6
  • 8.1.2 (cordova-lib@8.1.1) 8.1.2 (cordova-lib@8.1.1)
  • TypeScript打字稿
  • Visual Studio Code视觉工作室代码

you can use like below你可以像下面这样使用

<img src="gender == 'M'? 'your image path for male': 'your image path for Female'"/>

using above no need to use ngIf directive使用上面不需要使用 ngIf 指令

Rather than using images you can go for font awesome icons您可以使用字体真棒图标,而不是使用图像

<div *ngIf="gender == 'F'; else elseBlock">
  <i class="fa fa-venus" aria-hidden="true">
  </i>
</div>
<ng-template #elseBlock>
  <i class="fa fa-mars" aria-hidden="true">
  </i>
</ng-template>

I solved,我解决了,

 <img *ngIf="response.gender == 'F'" src="female.png" slot="start" /> <img *ngIf="response.gender == 'M'" src="male.png" slot="start" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM