我所有的指令都使用相同的範圍,我希望我的指令能夠自己操作。如何防止範圍在指令中共享?Angular?
指令:
app.directive('headerSort', function() {
return {
restrict: 'A',
controller: function ($scope, $element, $attrs) {
$scope.caption = $attrs.caption;
$scope.doSort = function() {
$scope.orderField = $attrs.headerSort;
$scope.reverse = !$scope.reverse;
};
},
template: '<div data-ng-click="doSort();">' +
'{{caption}}' +
'<i class="icon-sort"></i>' +
'</div>'
};
});
HTML:
<th data-header-Sort="FullName" data-caption="Full name"></th>
<th data-header-Sort="FirsName" data-caption="First name"></th>
<th data-header-Sort="Age" data-caption="Age"></th>
其結果是,所有列的值是 '年齡' 和排序年齡。我當然希望每一列都是自己的專欄。我怎樣才能做到這一點?
UPDATE: 忘了提,orderField
和reverse
在ng-repeat | orderBy
使用:
<tbody id="customerRows" data-ng-repeat="customer in customers | orderBy:orderField:reverse">
您可能感興趣的AngularUI的ng-grid指令@ http://angular-ui.github.io/ng-grid/ –