1

I have a router in Angular:

var scenarioManagementModule = angular.module( 'scenarioManagementModule', ['ngResource', 'scenarioModule'])
.config(['$stateProvider', '$urlRouterProvider',
  function( $stateProvider, $urlRouterProvider){
    $stateProvider.state( 'scenario_management', {
        url:         '/scenario_management',
        templateUrl: 'index.html',
        controller:  function( $scope, $state ) {
            $state.transitionTo('scenario_management.scenarios', { reload: true, inherit: false, notify: true });
        }
    });

    $stateProvider.state( 'scenario_management.scenarios', {
        url:         '/scenarios',
        templateUrl: '/scenarios.html',
        controller:  'ScenarioListController',
        resolve:     {
            scenarios_data:  function( $stateParams, Scenario ){
                return Scenario.list();
            }
        }
    });

    $stateProvider.state( 'scenario_management.scenarios.create', {
        url:            '/create',
        templateUrl:    '/scenario.create.html',
        controller:     'ScenarioCreateController',
    });
}]);

My views are set up correctly. All parent templates have their ui-views at the right place, and when I try to access the create page by pasting the url in the browser, it works perfectly.

However, when I programmatically try to invoke the create state with the following code, something strange happens:

$state.transitionTo('scenario_management.scenarios.create', $stateParams, { reload: true, inherit: false, notify: true });

Through console.log, I can see the create state being loaded as desired, however when this state finishes loading, immediately afterwards its parent state starts loading again. As a result, the create state disappears again. And also according to the browser's url, I am now in the parent state again.

Am I doing something wrong? Can someone tell me what's going on, and how can I make sure that the create state stays loaded in?

7
  • I think you should use state.go. It's based on transitionTo. I don't see any problem in your config. Commented Nov 4, 2015 at 17:36
  • from doc: Low-level method for transitioning to a new state. $state.go uses transitionTo internally. $state.go is recommended in most situations. angular-ui.github.io/ui-router/site/#/api/… Commented Nov 4, 2015 at 17:37
  • I tried that, but that didn't resolve the issue unfortunately. Commented Nov 4, 2015 at 17:39
  • In your first state you have controller: function( $scope, $state ) { $state.transitionTo('scenario_management.scenarios', { reload: true, inherit: false, notify: true }); } this is the reason. Try to delete it. Commented Nov 4, 2015 at 17:43
  • If you don't want load this state properly you can use abstract: true. Commented Nov 4, 2015 at 17:44

1 Answer 1

2

If you don't want load this state properly you can use abstract: true.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.