I'm trying to clean up some of my HTML code by creating an AngularJS directive for sorting columns in my tables. When I click on the heading, no errors are logged, but nothing happens, the column isn't reordered.
directive
Glenn.directive('sort', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
scope.predicate = 'title';
scope.reverseSort = false;
element.on('click', function() {
scope.predicate = attrs.sort;
scope.reverseSort != scope.reverseSort;
});
}
}
});
html
<th>
<a sort="title" href="">Title
<span ng-show="predicate == 'title'">
<span ng-show="!reverseSort"><i class="fa fa-caret-up"></i></span>
<span ng-show="reverseSort"><i class="fa fa-caret-down"></i></span>
</span>
</a>
</th>
Where am I going wrong here? Do I need to use something like $apply to make the sorting changes appear in the dom?