I'm not sure why this code isn't running. I'm trying to set up a simple counter that increases every second using angulars $interval wrapper.
angular.module('app').controller('testController', function($scope, $interval){
var set_counter = function(){
var start_time = new Date(2014, 09, 02, 0,0,0,0).getTime()
var time_counter = new Date().getTime()
$scope.counter = Math.ceil(time_counter / 1000000 + ((time_counter / 1000 - start_time / 1000) * 0.5)).toLocaleString();
console.log($scope.counter);
}
$interval(set_counter(), 1000);
});
The issue is in on that line
$interval(set_counter(), 1000);
you are calling the "set_counter" right away not passing it to "$interval" as a callback.
Fix:
$interval(set_counter, 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With