ngIf 依赖于 Angular 4 中的数字绑定图像

编程入门 行业动态 更新时间:2024-10-12 05:47:25
本文介绍了ngIf 依赖于 Angular 4 中的数字绑定图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

 <div *ngIf="user?.data.apps.details[0].acknowledged as fooIcon"><img *ngIf="fooIcon === "1" " src="./app/img/icones_sized/tick.png"/><img *ngIf="fooIcon === "0" " src="nothing_appears"/>

如果我的.acknowledged"返回1",我正在尝试显示图像,如果它返回0",则不应显示任何内容......它适用于字符串但不适用于数字......我不我真的不明白为什么..

解决方案

你应该使用 *ngIf...else, as

 <img src="./app/img/icones_sized/stable_arrow_small.png"/></ng-模板><div *ngIf="user?.data.apps.details[0].acknowledged===1;else loading;"><img src="./app/img/icones_sized/tick.png"/>

 <td *ngFor="let user of userService.users | async">
 <div *ngIf="user?.data.apps.details[0].acknowledged as fooIcon">
 <img *ngIf="fooIcon === "1" " src="./app/img/icones_sized/tick.png"/>
 <img *ngIf="fooIcon === "0" " src="nothing_appears"/>
 </div> 

I am trying to display an image if my ".acknowledged" is returning "1" and if it return "0" nothing should be displayed...It works with a string but not with a number..I don't really understand why..

解决方案

You should be using *ngIf...else, as

    <ng-template #loading>
        <img src="./app/img/icones_sized/stable_arrow_small.png"/>
    </ng-template>
    <div *ngIf="user?.data.apps.details[0].acknowledged===1;else loading;">
      <img src="./app/img/icones_sized/tick.png"/>
    </div>

这篇关于ngIf 依赖于 Angular 4 中的数字绑定图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 10:36:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1001924.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   图像   数字   依赖于   ngIf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!