I am using angular. I want to implement stopwatch. I have a list which consists of one or more objects. I have a start timer and end the timer button for each item. when I click on the start button this should start the timer for the specific item & when I click on the end timer button this should pause the timer so that I can restart the time. but only one timer should run at a time. if Item A timer is started & if click on the start timer button of Item B it should pause the previous timer & start the new timer for Item B.
allUserTaskArr = [
{
'name': 'abc',
'id':1,
'start': true,
'end': false
},
{
'name': 'xyz',
'id':1,
'start': true,
'end': false
}
];
startTask (item) {
if(item.start) {
item.end = true;
item.start= false;
}
}
EndTask (item) {
if(item.end) {
item.end = false;
item.start= true;
}
}
<div class="row no-gutters">
<div class="card width hr" *ngFor="let item of allUserTaskArr">
<div class="card-header">
{{item.due | date}}
</div>
<div class="card-body pad-125">
<div class="row no-gutters">
<div class="col-md-12">
{{item.name}}
<div class="float-right">
<button class="btn btn-info mar-l-r-0-5" *ngIf="item.start" (click)="startTask(item)">Start Timer</button>
<button class="btn btn-danger mar-l-r-0-5" *ngIf="item.end" (click)="EndTask(item)">End Timer</button>
</div>
</div>
</div>
</div>
</div>
</div>