简体   繁体   中英

Redirect after X seconds AngularJS

I already saw this thread but it uses ui-router and I'm only using the $routeProvider of AngularJS. The code in the thread is:

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

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

    }])

How can I use it with my routeProvider since I am not using ui-router ? Thank you in advance.

您需要使用$location服务

$location.path('/anotherURL');

By $location method :

code:

.controller('HomeController', ['$scope', '$state', '$location',
                                    function($scope, $state, $location) {    
      $location.path('/appurl');

        }])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM