I have a simple scenario
<thead grid-columns pager-info="pagerInfo" onsort="onSort()">
<tr>
<th width="15%"><column sortby='FName'>Name</column></th>
<th width="17%"><column sortby='Mobile'>Number</column></th>
</tr>
</thead>
The idea is that since ALL my columns need an onsort
defined, I can just define it once on the parent.
But, why doesn't my child directive (column) have it's $parent
set to the grid-columns directive? Instead, scope.$parent
is set to the controller scope, so I can't work out how to access my parent directive scope from my child directive.
Both of the directives have an isolated scope, and my child directive transcludes:
ngApp.directive('gridColumns', function () {
// Attribute-based wrapper round the columns that allows us to capture the pagerInfo and set a sort handler.
return {
restrict: 'A',
scope: {
pagerInfo: '=',
onsort: '='
}
};
});
ngApp.directive('column', function () {
return {
restrict: 'E',
transclude: true,
replace: true,
scope: {
sortby: '@'
},
template: "<span><a ng-click='sort()' ... </span>",
link: function (scope, el, attrs) {
scope.sort = function () {
// I want to call scope.$parent.onsort, but scope.$parent is the controller !
// scope.$parent.onsort(scope.sortby);
};
}
};
});