angular - 角度 *ngIf 条件
问题描述
我正在使用这两个条件,问题是按钮都出现了,而实际上只应该出现一个。
即如果="currentState == 'pause'"
一个按钮出现,否则如果="currentState == 'pause' && 'taskdate'> 'data.key.deadline'"
另一个按钮出现......问题是两者都出现而不仅仅是1。我认为这是因为currentState在两者中都是真的......我该如何解决这个问题?
html
<div *dxTemplate="let data of 'cellTemplate'">
<button type="button" data-toggle="dropdown" class="btn ClassPlay">
<img style="width: 35px;" *ngIf="currentState=='pause' && taskdate <= data.key.deadline" src="./assets/play.svg">
<img style="width: 35px;" *ngIf=" currentState=='pause' && taskdate > data.key.deadline" src="./assets/PlayRed.svg">
<div *ngIf="currentState=='start'" src="./assets/playV.svg">
<img style="width: 38px;" *ngIf="currentRowIndex === data.rowIndex" src="./assets/playV.svg">
<img style="width: 38px;" *ngIf="currentRowIndex != data.rowIndex" src="./assets/PlayGrey.svg">
</div>
</button>
</div>
零件
taskdate = new Date();
解决方案
不需要额外的单引号。当您使用'taskdate'
时,它被评估为字符串。我相信,taskdate
并且data?.key?.line
是变量:
<img style="width: 35px;"
*ngIf="currentState == 'pause' && (taskDate <= data?.key?.line)"
src="./assets/pl.svg">
<img style="width: 35px;"
*ngIf="currentState == 'pause' && (taskdate > data?.key?.line)"
src="./assets/ap.svg">
推荐阅读
- java - 没有找到 Spring Boot Thin Launcher exec jar
- mysql - 当需要几种连接类型时,是否可以抑制 UNION?
- sass - 如何将 '%' 添加到值中?
- opencv - 关于在 Debian 10 arm64 上安装 libgtk-3-dev 的问题
- javascript - 包装一个函数来延迟该函数的调用?(在 React 中删除任务)
- sql - 检索最新日期预言机
- android - 如何通过下拉刷新 Expo Webview 中的页面?
- google-cloud-platform - 是否可以在 Cloud Run 服务中公开 5001 (HTTP) 和 5672 (TCP) 端口?
- pulp - 约束:我可以融化克数、卡路里和百分比作为约束吗?
- php - PHP 帮助、MySQL 和查询中的行号