为什么我的函数toggleCategory函数没有被触发?
指令
app.directive('asideFilter', function() {
return {
restrict: 'E',
scope: {
toggleCategory: '=&onToggleCategory'
},
transclude: true,
templateUrl: 'assets/directives/asideFilter/asideFilter.html',
link: function(scope, element, attrs){
}
};
});;
指令模板
<div ng-click="toggleCategory({id: 'teste'})">TEST</div>
父范围
$scope.onToggleCategory = function () {
console.log('onToggleCategory');
}
家长来电
<aside-filter toggle-category="onToggleCategory({id: 'test '})" categories="categories" />
答案 0 :(得分:1)
您也可以像这样调用父控制器函数
app.directive('asideFilter', function() {
return {
restrict: 'E',
scope: {
toggleCategory: '&',
},
transclude: true,
templateUrl: 'assets/directives/asideFilter/asideFilter.html',
link: function(scope, element, attrs){
scope.toggleCategoryClick = function (value) {
scope.toggleCategory(value);
}
}
};
});
指令模板
<div ng-click="toggleCategoryClick({id: 'teste'})">TEST</div>
指令元素
<aside-filter toggle-category="onToggleCategory({id: 'test '})" categories="categories" />