3

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!

2
  • Why not just use the ui-sref directive eg <a ui-sref="myState">go</a> 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). Commented Jul 27, 2014 at 18:37

1 Answer 1

10

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

controllers.controller("MyController", function($scope, $state){
    $scope.go = function(){
        $state.go('new-state');
    };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.