angular-breadcrumb icon indicating copy to clipboard operation
angular-breadcrumb copied to clipboard

nested states and viewContentLoaded not called

Open Necko75 opened this issue 11 years ago • 4 comments

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 ...

Necko75 avatar Oct 02 '14 10:10 Necko75

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 ?

ncuillery avatar Oct 04 '14 08:10 ncuillery

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

geobourazanas avatar Oct 07 '14 05:10 geobourazanas

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

halilb avatar Oct 16 '14 18:10 halilb

@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 :)

sebastienvermeille avatar Feb 12 '16 07:02 sebastienvermeille