Is there a way to get a list of child states in angular -ui-router?

I am creating an angular application and for part of the application, I want to have a menu with dynamically populated options based on the available states. Here is the simplified part of my state configuration:

$stateProvider.state('root.type.list.controls', {
  url: '/controls',
  templateUrl: 'views/controls.html',
  controller: 'ControlsCtrl',
  data: {
    title: 'Controls'
  }
})
.state('root.type.list.items', {
  url: '/items',
  templateUrl: 'views/items.html',
  controller: 'ItemsCtrl',
  data: {
    title: 'Items'
  }
})

I would like to be able to populate the drop-down menu with headers from each immediate child 'root.type.list', depending on what is in the dataconfiguration section . Is there a way to get a list of all child states for a particular state?

+3
source share
1 answer

Finished with $state.get()and follow these steps:

function _children(stateName) {
  return _.filter($state.get(), function(config) {
    return stateName === config.name.slice(0, stateName.length) &&
      config.name.split('.').length === stateName.split('.').length + 1;
  });
}
+2
source

All Articles