我有州brand
。在这个州的模板上,我有一些面包屑。例如,当我转到嵌套状态 brand.collections
时,我需要更新brand
状态的面包屑。
我该如何做到这一点?
.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'
})
答案 0 :(得分:3)
$scope.$emit('changeParentVar',<newVal>);
在BrandController里面
$scope.$on('changeParentVar',function(event,newVal){
event.stopPropagation();
variable = newVal;
});
参考http://docs.angularjs.org/api/ng。$ rootScope.Scope#methods_ $ on