David D. David D. - 2 months ago 27
AngularJS Question

How to auto redirect after X seconds in AngularJS?

What is the right way to do this in AngularJS? I didn't find any simple answer to this.

I'd like to :


  1. Load a page

  2. Wait for X seconds

  3. Being automatically redirected to another page after these seconds.



Note: I'm using ui-routing (states) to perform redirections

Thanks.

Answer

This works (thanks PSL):

.controller('SeeYouSoonCtrl', ['$scope', '$state', '$timeout',
                                function($scope, $state, $timeout) {

    $timeout(function() {
      $state.go('AnotherState');
      }, 3000);

    }])