Skip to content

Accessing resolved data in Transition state's parents #2946

Closed
@charlie-s

Description

@charlie-s

This is similar to #2864, but I also need to access parent state's resolved values. I've checked the source code but don't see how the Transition methods could be used to get this data from a parent state.

Given this router definition:

$stateProvider
    .state('company', {
        url: '/company/:id',
        resolve: {
            'company': ['$stateParams', 'Company', function($stateParams, Company) {
                return Company.findById($stateParams).$promise;
            }],
            $title: ['company', function(company) { 
                return company.name;
            }]
        }
    })
    .state('company.overview', {
        url: '/overview',
        resolve: {
            $title: function() { return 'Overview'; }
        }
    });

and a directive where I attempt to basically gather breadcrumb information about the current hierarchy:

$transitions.onSuccess({from: '*.*', to: '*.*'}, function(Transition) {

    $rootScope.$title = Transition.getResolveValue('$title');

    $rootScope.$breadcrumbs = [];

    var state = $state.$current;

    while (state) {
        if (state.resolve && state.resolve.$title) {
            $rootScope.$breadcrumbs.unshift({
                title: state.resolve.$title,
                href: $state.href(state)
            });
        }
        state = state.parent;
    }
});

How can I get the resolved value of $title on the current state's parent?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions