1

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?

1
  • Please add the other operations using $timeout. So we can deliver you a nice and stable solution. I promise, in the end you dont need even one $timeout. Commented Dec 2, 2016 at 9:45

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

8 Comments

He said, there are other timeouts. In that way your solution is not stable/clean. You need to ensure that all other render operations are finished. Working with delays is such a problem in JavaScript because it is much depending on the client performance. This could break your application.
@lin, you are right, its not a good solution to use 500 milliseconds for me. The problem is that were used other $timeout, and I don't know when they finish their execution.
@Labo29, just add the "other operations code" into your question. We will find a solution.
The delay is exactly what was being asked for in that it priorities the start of execution. If something needs to be delayed until the end of execution, see the second part of my answer.
@OliverSalzburg ok, if using delays is the only way, I will search for another solution which doesn't use $timeout. I don't like to put delays in page, they are too unreliable.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.