简体   繁体   中英

angularjs ui-router come back to the current state

I am using angular ui-router in my application. I have a 2 states, create-app and list-apps . When i create an app i transition to the state create-app with param id equal to null . The problem is that when i am on state create-app i cannot transitionTo create-app . The use case is that if in the middle of creating an app i want to create another app i have to transitionTo create-app but since the state is already create-app ui-router does not change the state. I know this because i looked for firing of $stateChangeStart and $stateChangeSuccess event. None of these fire. But when i am on 'list-apps' or even create-app with param id not equal to null (which is edit app) i am able to come to state create-app .

$scope.createApp = function() {
       $state.transitionTo('create-app', {id: null});
    };

SO i tried this

$scope.createApp = function() {

            if ($state.current.name == 'create-app' && $state.params.id == null) {  // when the state is create-app and not list-apps or edit-app
                   $state.current.name = '';    
            }
            $state.transitionTo('create-app', {id: null});

    };

In this when the state is create-app and the i again try to come to the same state i change the state name to '' and params to null so angular finds the fromState and toState different . Even this does not work. Is there some way i can do this?

You can use $state.reload(). There's a discussion on github about this here .
Use it like this:

$state.reload();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM