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

nested states and viewContentLoaded not called #44

Open Necko75 opened 10 years ago

Necko75 commented 10 years ago

Hi,

There is a bug with the function $viewContentLoaded in your directive. I have nested states which are calling the same controller, and the same view template html. In my controller, in terms of the childs states, I apply filters on my template results. So, the state change but not the breadcrumb.

In order to fix it, I have added a listener on $stateChangeSuccess.

$stateProvider.state('a.b', {
    url: '/:category-:categoryId',
    views: {
        '@a': {
            templateUrl: 'partials/layout.html',
            controller: 'ABController'
        },
        '@a.b': {
            templateUrl: 'partials/index.html',
            controller: 'AControler'
        }
    },
    data: {
        ncyBreadcrumbLabel: 'Part_category'
    }
});
$stateProvider.state('a.b.make', {
    url: '/brand-:brandLabel-:brandId',
    views: {
        templateUrl: 'partials/index.html',
        controller: 'ABController'
    },
    data: {
        ncyBreadcrumbLabel: 'by_brand'
    }
});
$stateProvider.state('a.b.make.model', {
    url: '/:slugModelLabel-:modelId',
    views: {
        templateUrl: 'partials/index.html',
        controller: 'ABController'
    },
    data: {
        ncyBreadcrumbLabel: 'by_model'
    }
});

=======

$rootScope.$on('$viewContentLoaded', function () {
    renderBreadcrumb();
});

$rootScope.$on('$stateChangeSuccess', function () {
    renderBreadcrumb();
});

I am not sure how ui-rooter works, but if the templateUrl not change, so the event $viewContentLoaded is not triggered ...

ncuillery commented 10 years ago

I have met this bug few months ago, I solved it by upgrading the ui-router to the version 0.2.10.

Which version of ui-router do you use ?

geobourazanas commented 10 years ago

I use ui-router version 0.2.11 and the bug is still there. I replaced $viewContentLoaded with $stateChangeSuccess and worked like a charm.

halilb commented 10 years ago

Thanks @geobourazanas , that change has solved my problem too.

sebastienvermeille commented 8 years ago

@ncuillery @geobourazanas
Excuse me I encounter the same problem.

It is something fixed now ? I tried to use :

$rootScope.$on('$viewContentLoaded', function () {
    renderBreadcrumb();
});

$rootScope.$on('$stateChangeSuccess', function () {
    renderBreadcrumb();
});

but it doesn't know the method "renderBreadcrumb();" do I have to edit the directive directly ???

Thank you for your tips :)