Skip to content

Support 'children' property on stateConfig #346

Closed
@marklagendijk

Description

@marklagendijk

Currently there are 3 ways of defining states:

  1. Using 'dot' notation. For example name: 'contacts.list'
  2. Using the parent property with the parent name as string. For example: parent: 'contacts'
  3. Using the parent property with the parent object. For example parent: contacts (where 'contacts' is an stateObject)

To me it would make sense to also support a 'children' property. This would be used as follows:

$stateProvider
  .state('contacts', {
    children: [
      {
        name: 'list'
      }
    ]
  });

In the end it is all a matter of preference. I don't think it matters a lot which ways are supported. Currently I use the following function to support the method described above.

function setState(state){
    $stateProvider.state(state);

    if(state.children && state.children.length){
        state.children.forEach(function(childState){
            childState.parent = state;
            setState(childState);
        });
    }
}

What would be more useful is the fact that you would have the children property available afterwards. This way a state would know which children it has. Which would allow for things like:

<ul>
    <li ng-repeat='childState in $state.current'>
        <a ui-sref='childState.name'>{{ childState.name }}</a>
    </li>
</ul>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions