如何做一个angularjs页面重定向页面? [英] How to do a page redirect page in angularjs?

查看:1727
本文介绍了如何做一个angularjs页面重定向页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的网页重定向到不同的网页在我的应用程序。

问题是,所有的网址设置都在我的app.js与 UI的路线,我需要重定向我的控制器中发生的。

所以app.js。

 的app.config(函数($ stateProvider){
    $ stateProvider
        .STATE('第一',{
            网址:'/第一',
            templateUrl:first.html
        })
        .STATE('第二',{
            网址:'/秒,
            templateUrl:second.html
        })
})

我的控制器文件

  app.controller。('firstCtrl',函数(){    $ scope.clickThis =功能(){
        //需要重定向到第二页...
    }})

我如何重定向到不同的网页我的控制器内?


解决方案

  app.controller。('firstCtrl',[$范围,$状态功能($范围,$州){    $ scope.clickThis =功能(){
        $ state.go(第二);
    }}]);

I am trying to redirect my page to different page in my app.

The problem is that all the url settings are all in my app.js with ui-route and I need the redirect happens inside my controller.

so 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...
    }

})

How do I redirect to different page inside my controller?

解决方案

app.controller.('firstCtrl' ,["$scope", "$state", function($scope, $state){

    $scope.clickThis=function() {
        $state.go("second");
    }

}]);

这篇关于如何做一个angularjs页面重定向页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆