alucardu
alucardu

Reputation: 129

Multiple select options, but reverse the order of one option

I have a select element that has 2 options. Created_at and Release_date. These options sort the order of the ng-repeat in the view. So when I select created_at the list gets ordered from first to last created, when I select release_date it orders the list from first release date to the last.

I would like to add a inverse to the created_at option. Because I want the record that's been created last to be the first record in the list. But I don't want to change the order of the release_date list.

$scope.select = function(){
  orderByClick = this.selectedItem.value;
  orderBy();
}

var orderBy = function(){
  var orderBy = $filter('orderBy');
  $scope.movies = orderBy($scope.movies, orderByClick);
  console.log('orderBy')
}

I've created a plunker with the select option, http://plnkr.co/edit/HCncjLYyPD0EiyHFDOs9?p=preview

Upvotes: 1

Views: 159

Answers (1)

DamianoPantani
DamianoPantani

Reputation: 1386

Do you mean this?

<input type="checkbox" ng-model="descendingOrder"> Descending?

$scope.movies = $scope.descendingOrder ? orderBy($scope.movies, orderByClick) : $scope.movies.reverse();

Upvotes: 1

Related Questions