Labo29
Labo29

Reputation: 117

AngularJS - Execute function in controller for last using $timeout()

In the main controller I wrote:

angular.element(window).load(function () {
    $timeout(function () {
        scrollAnchor(); // Scroll to Anchor
    });
});

I'd this to to scroll to the last operation right after all elements were rendered. The problem is that there are also other $timeout() with other functions. So the scrolling is not the last operation. Is there a way to introduce a priority over the functions executed in $timeout?

Upvotes: 1

Views: 613

Answers (1)

Oliver Salzburg
Oliver Salzburg

Reputation: 22099

When you don't supply a delay parameter, the function is called on the next digest cycle.

So, to make sure that certain delayed executions are performed after others with the same parameters, just set a higher delay.

$timeout(scrollAnchor, 500);

Or you could fire an event when you know that "everything else" is done and then scroll to where you want to scroll.

Upvotes: 2

Related Questions