I am currently managing a set of table columns that can be sorted in ascending and descending order. Previously, the sorting logic was implemented within each ng-click
and ng-show
directive in the following way:
HTML
<a style="color:black" href="" ng-click="sortReverse = !sortReverse; changeSortType('id')">
Group id
<span ng-show="sortType == 'id' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'id' && sortReverse" class="fa fa-caret-up"></span>
</a></th>
CONTROLLER
$scope.sortType = 'count';
$scope.sortReverse = true;
$scope.changeSortType = function (sortType){
$scope.sortType = sortType;
};
$scope.itemSortValue = function (item) {
return Service.sort(item, $scope.sortType)
};
We now aim to streamline this process by implementing a method that achieves the same outcome, reducing the amount of code in the HTML.
Unfortunately, I have been struggling to figure out how to achieve this using AngularJS. I have attempted various approaches without success. While I have come across some suggestions online, they have not yielded the desired results. Could someone please provide guidance on the code implementation?