I am currently utilizing Angular to create a functional counter like so:
<button ng-click="order.startOperation(operation)">
<p ng-if="counter.start"></p>
</button>
When the button is clicked, it triggers a function that initiates the counter. I have incorporated an ng-if
statement to display the minutes and seconds as they tick by once the counter starts running. It's worth noting that this same button can also be used to halt the counter.
function startOperation(operation) {
var operation.lastStart = Date.now();
operation.playing = true;
}
// Pause an operation timer.
function pauseOperation(operation) {
var operation = vm.data.operations[vm.data.operations.indexOf(operation)];
if (!operation.start) {
operation.start = operation.lastStart;
}
operation.end = Date.now();
// Calculate the elapsed seconds.
operation.partialTime = operation.partialTime || 0;
operation.partialTime += Math.ceil((operation.end - operation.lastStart) / 1000);
dataService.update();
}