如何在angularjs中做一个页面重定向页面

How to do a page redirect page in angularjs?

本文关键字:一个 重定向 angularjs      更新时间:2023-09-26

我正在尝试将我的页面重定向到我的应用程序中的不同页面。

问题是,所有的url设置都在我的app.js与ui-route,我需要重定向发生在我的控制器内。

所以app.js。

app.config(function($stateProvider) {    
    $stateProvider
        .state('first', {
            url: '/first',
            templateUrl: 'first.html'
        })
        .state('second', {
            url: '/second',
            templateUrl: 'second.html'
        })
})

my controller file

app.controller.('firstCtrl' , function(){
    $scope.clickThis=function() {
        //need to redirect to second page...
    }
})

我如何重定向到不同的页面在我的控制器?

app.controller.('firstCtrl' ,["$scope", "$state", function($scope, $state){
    $scope.clickThis=function() {
        $state.go("second");
    }
}]);