最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angularjs ui router manual navigation - Stack Overflow

programmeradmin5浏览0评论

I want to manually change the current state within my controller using the ui router.

I have the following code at the moment:

<button ng-click="go()">Go</button>

    controllers.controller("MyController", function($scope){
        $scope.go = function(){
            //Manually change state
        };
    });

Is there something like

$uiRouter.changeState("mystate"); ?

Thanks in advance!

I want to manually change the current state within my controller using the ui router.

I have the following code at the moment:

<button ng-click="go()">Go</button>

    controllers.controller("MyController", function($scope){
        $scope.go = function(){
            //Manually change state
        };
    });

Is there something like

$uiRouter.changeState("mystate"); ?

Thanks in advance!

Share Improve this question edited Jul 9, 2014 at 2:25 rageandqq 2,29120 silver badges24 bronze badges asked Jul 9, 2014 at 2:10 Himmet AvsarHimmet Avsar 1,53116 silver badges23 bronze badges 2
  • Why not just use the ui-sref directive eg <a ui-sref="myState">go</a> – craigb Commented Jul 24, 2014 at 2:51
  • Because I needed to do some actions before changing the state (registering an user for example before changing the state). – Himmet Avsar Commented Jul 27, 2014 at 18:37
Add a ment  | 

1 Answer 1

Reset to default 10

you can use $state.go or $state.transitionTo (https://github./angular-ui/ui-router/wiki/Quick-Reference#statetransitiontoto-toparams--options)

controllers.controller("MyController", function($scope, $state){
    $scope.go = function(){
        $state.go('new-state');
    };
});
发布评论

评论列表(0)

  1. 暂无评论