Change parent variable using Angular and UI-Router

I have a condition brand. On the template for this condition, I have several breadcrumbs. When I go into a nested state brand.collections, for example, I need to update the breadcrumbs in the state brand.

How can i do this?

.state('brand', {
    url: '/brands/:brandId/:brandName',
    templateUrl: 'js/modules/brands/partials/brand.html',
    controller: 'BrandController',
})

.state('brand.home', {
    url: '/home',
    templateUrl: 'js/modules/brands/partials/brand.home.html',
    controller: 'BrandController'
})

.state('brand.collections', {
    url: '/collections',
    template: 'Some collections',
    controller: 'CollectionsController'
})
+3
source share
1 answer

inside CollectionsController

$scope.$emit('changeParentVar',<newVal>);

inside BrandController

$scope.$on('changeParentVar',function(event,newVal){
event.stopPropagation();
variable = newVal;
});

Link http://docs.angularjs.org/api/ng . $ rootScope.Scope # methods_ $ on

+3
source

All Articles