Whisher
Whisher

Reputation: 32726

angularjs $timeout without delay parameters reason

In a few script I can find for instance

$timeout(function () {
    $scope.my = 1;            
});

instead of simply

$scope.my = 1;

What's the purpose to call $timeout without delay?

Upvotes: 33

Views: 8760

Answers (1)

Davin Tryon
Davin Tryon

Reputation: 67296

This is a hack. :) But usually the intention is to wait until the end of the $digest cycle and then set $scope.my to 1. Timeouts are called after all watches are done.

Upvotes: 54

Related Questions