ncuillery / angular-breadcrumb

Generate a breadcrumb from ui-router's states
http://ncuillery.github.io/angular-breadcrumb/
MIT License
785 stars 183 forks source link

Why toParams.ncyBreadcrumbLabel is undefined inside a run block? #153

Open josoroma-zz opened 8 years ago

josoroma-zz commented 8 years ago

Hi!

I am trying to create/mimic a kind of custom stack for the current breadcrumbs behavior, but I notice that toParams.ncyBreadcrumbLabel is always undefined even if console.log(toParams) displays its value.

.run(['$rootScope', '$state', '$stateParams', '$breadcrumb', '$templateCache',
function run ($rootScope, $state, $stateParams, $breadcrumb, $templateCache) {
    $rootScope.statesStack = [];

    $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
        $rootScope.statesStack.push({
            'toState': toState,
            'toParams': toParams,
            'fromState': fromState,
            'fromParams': fromParams,
            'fromLabel': toParams.ncyBreadcrumbLabel
        });

        console.log('run - $rootScope.statesStack', $rootScope.statesStack);
    });
}]);

Any help would be great!

wosevision commented 8 years ago

Hello!

I can confirm the issue @josoroma is experiencing – it seems run blocks are only aware of the pre-resolved param ncyBreadcrumb despite console.log(toState) being able to see the entire resolved params (such as ncyBreadcrumbLabel).

I thought I might be able to mitigate it in a dirty way by using the $interpolate service in my run block to parse the label manually, but it doesn't have access to the proper scope to pull it off.

Any thoughts on where it's hiding? So far I haven't had any luck "promise-ing" it in either.