Nick Nick Nick Nick - 1 year ago 60
AngularJS Question

Auto-updatable values in angularJS

I have array of dates

$scope.dates = []
(
$scope.dates[0].date
). I need to create another array with auto-updateble(!) values of durations.


  • $scope.dates[i].duration = Date.now() - $scope.dates[i].date
    .



I want to create timer in seconds:

<tr ng-repeat="x in dates">
<td>{{x.date | date:'HH:mm:ss'}}</td>
<td>{{x.duration}}</td>


Edit: Probled solved

Answer Source

Call this function, it will maintain object in $rootScope object:

$rootScope.timerActivate = function () {

        console.log('activateTimer ::');
        if(!$rootScope.time)
        {
            $rootScope.time = {}
        }        
        var countDown = function () {

            var today = new Date();
            var hours = new Date().getHours();
            var hours = (hours + 24) % 24;
            var mid = 'am';
            if (hours == 0) { //At 00 hours we need to show 12 am
                hours = 12;
            }
            else if (hours > 12)
            {
                hours = hours % 12;
                mid = 'pm';
            }
            var minute = today.getMinutes();
            var sec = today.getSeconds();
            $rootScope.time.hours = (hours < 10) ? '0' + hours : hours;
            $rootScope.time.minutes = (minute < 10) ? '0' + minute : minute;
            $rootScope.time.seconds = (sec < 10) ? '0' + sec : sec;
            $rootScope.time.blink = (sec % 2) ? ':' : ' ';
            $rootScope.time.mid = mid;
            $timeout(countDown, 1000);
        };

        $timeout(countDown, 1000);

    };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download