0

I am a newbie of angularjs using angularjs1.6.4 version with angular-ui-router version 1.0.3. I have seen a lot of posts getting previous state by using $stateChangeSuccess but this event is deprecated above ui-router version 1.0.0 (reference from here) so for that i have to use $transitions.onSuccess but i don't get it how to get previous state. So far i have written this and its displaying message "stateChange success" when state change. But i need some example to proceed further.

App.js:

.run(function ($transitions) {
    $transitions.onSuccess({}, function () {
        console.log("statechange success");
    });
MTA
  • 1,033
  • 5
  • 16
  • 37
  • The callback function passed to onSuccess() is documented here: https://ui-router.github.io/ng1/docs/latest/interfaces/transition.transitionhookfn.html. You can see that it takes a Transition object as argument, documented here: https://ui-router.github.io/ng1/docs/latest/classes/transition.transition-1.html. You can see that it has a $from() method. – JB Nizet Jun 03 '17 at 11:10
  • did my answer work for your question? I have used $stateChangeSuccess before in my project. if it worked can you tick my answer – hasan Jun 03 '17 at 17:30

1 Answers1

1

This is what i want. An example for going back to a previous state with a refresh using $transitions.onSuccess instead of $stateChangeSuccess

.run(function ($transitions, $state) {
    var previousState;
    var previousStateParameters;
    $transitions.onSuccess({}, function (transition) {
        previousState = transition.from().name;
        previousStateParameters = transition.params('from');
    });
    $transitions.back = function () {
        $state.go(previousState, previousStateParameters, { reload: true });
    }
});
MTA
  • 1,033
  • 5
  • 16
  • 37