As a backend developer, I've been working tirelessly to create a timer by comparing two different date formats. While the initial part of the script works perfectly, I face challenges when trying to make a recursive call as nothing seems to bind.
I've experimented with various approaches such as passing it into a function, utilizing $interval, setInterval, and more. The core issue lies in my inability to extract the loop value and bind it to my DOM.
Below is a snippet of my code where I set all variables for the countDown() function:
$scope.timer.list = {};
$scope.timer.date = new Date();
$scope.timer.list.D = '00';
$scope.timer.list.M = '00';
$scope.timer.list.Y = '00';
$scope.timer.list.h = '00';
$scope.timer.list.m = '00';
$scope.timer.list.s = '00';
$scope.begin = {};
$scope.begin.date = {};
$scope.begin.timer = {};
$scope.counter = {
show: false,
text: '00:00'
};
setInterval(function() {
$scope.obj = {
show: $scope.countDown($scope.privateshowcase.begin_at).show,
text: $scope.countDown($scope.privateshowcase.begin_at).text
}
$scope.counter = $scope.obj;
}, 1000);
In addition, here is the function definition:
$scope.countDown = function(begin) {
// Function logic here...
}
'begin' format: 'YYYY/MM/DAY HH:MM:SS'
Despite facing some hurdles, I have managed to develop a very functional timer that converts numbers from 1 to 9 into 01 to 09, transforms 60 into 00, and can effectively compare two distinct times.