angular - 服务继续运行,但按钮状态发生变化
问题描述
我有一个数据表,在表的每一行中都有一个带按钮的列。为了只执行单击它的行的按钮,在开始/暂停计时器功能中,我传递了该行的索引,以便只执行该行的按钮。
我在服务中开发了这些功能,以便在更改页面时计时器继续工作而不会被破坏。
我的问题是,当我运行计时器并更改页面时,按钮状态会发生变化,即我单击播放,它变成绿色,当我更改页面并返回确认按钮状态时,它不是绿色。我认为我的问题是当我更改页面时它会丢失行索引,因为该服务继续工作。
有谁知道我该如何解决这个问题?
HTML
<div class="row">
<button type="button" data-toggle="dropdown" class="btn ClassPlay">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngIf="currentState=='pause'" routerLinkActive="active"
(click)="currentState='start'; startTimer(data)">Start</a>
<a class="dropdown-item" *ngIf="currentState=='start'" routerLinkActive="active"
(click)="currentState='pause'; pauseTimer(data)">Stop</a>
</div>
</div>
解决方案
这是示例,请检查链接。
https://stackblitz.com/edit/angular-xn5gvl
我做了什么。
从服务中删除 trasform 方法并添加日期管道以显示格式时间
'HH:mm:ss'
将
currentRowIndex
物业投入使用将服务公开以将其用于这样的模板
taskService.method()
或taskService.property
添加
clearIntervale
到service.startTimer()
改变了
startTimer()
和pauseTimer()
component.ts
请注意,您也需要替换
*ngFor="let data of datas"
为*dxTemplate="let data of 'cellTemplate'"
和图像
推荐阅读
- c - 在另一个函数中访问 ac 字符串时出现分段错误
- c - C中分母的增量
- android - 了解 onWaveFormDataCapture 字节数组格式
- c - 为什么我在 VisualStudio 中收到 C4996 错误,而在 CodeBlocks 中没有收到任何错误?
- reactjs - yarn 网络连接有问题
- python - 计算在 Python 中打开的总行数
- html - Angular 6 应用程序中两个输入位于同一行时的表单验证
- java - 生成固定大小的随机字符串
- amazon-web-services - 无通信 - ec2 实例在不同子网中有两个接口
- r - 删除 R 中的重复组合