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
1 Answer
Reset to default 10you 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');
};
});