$ interval doesn't work, angularjs

I'm not sure why this code isn't working. I am trying to set up a simple counter that increments every second using an angular $ spacing 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);
});

      

+3


source to share


1 answer


The problem is this line

$interval(set_counter(), 1000);

      

you call set_counter right away without passing it $ interval as a callback.



Correction:

$interval(set_counter, 1000);

      

+1


source







All Articles