nested states and viewContentLoaded not called
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 ...
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 ?
I use ui-router version 0.2.11 and the bug is still there. I replaced $viewContentLoaded with $stateChangeSuccess and worked like a charm.
Thanks @geobourazanas , that change has solved my problem too.
@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 :)