kishu
kishu

Reputation: 73

Why does $timeout delay the whole page loading inside $ionicView.Enter?

As far as i know, $timeout is a promise object in angular, which means the code will go on running without waiting for the timeout to end.

However, when i used it in my ionic code, for some reason it did and the whole loading of the page froze for 6 seconds. Can you please explain why?

$scope.$on("$ionicView.Enter", function( scopes, states ) {
     $timeout(function(){
        // some function i wrote
     }, 6000);

});

Upvotes: 2

Views: 5943

Answers (1)

cortexlock
cortexlock

Reputation: 1476

Your assumption around the code continuing to run is wrong - otherwise what would the point of calling $timeout be? It's an Angular wrapper and recommended to use in place of window.setTimeout() but works exactly the same. The code above will execute after a 6000ms delay.

[ADDED] From the Angular API docs: "The return value of calling $timeout is a promise, which will be resolved when the delay has passed and the timeout function, if provided, is executed."

Upvotes: 1

Related Questions