The first is initializing $scope.clock
when the controller is created. That's the only time the first $scope.clock = new Date();
will be run. The second time, the function is updating the clock
property on the $scope
object, to set it with a new date.
This block would cause $scope.clock to be undefined until the timeout executes 10 seconds later:
function MyController($scope){
var updateClock = function()
{
$scope.clock = new Date();
};
setTimeout(function() { $scope.$apply(updateClock);}, 10000);
}
This block, $scope.clock is initialized when the controller is created:
function MyController($scope){
$scope.clock = new Date();
var updateClock = function()
{
$scope.clock = new Date();
};
setTimeout(function() { $scope.$apply(updateClock);}, 10000);
}