I have this small piece of code that uses setInterval method:
function MyController($scope) {
$scope.clock = new Date();
var updateClock = function()
Use the angular $interval service.
function($scope, $interval) {
$scope.clock = new Date();
var updateClock = function() {
$scope.clock = new Date();
};
$interval(updateClock, 1000);
}
If you use the JS setInterval() then you will need $scope.$apply() to your method.
var updateClock = function() {
$scope.clock = new Date();
$scope.$apply();
};
The better solution is to use $interval (angular)
$interval(updateClock, 1000);