最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sorting filter 'orderBy' doesn't work in AngularJS - Stack Overflow

programmeradmin2浏览0评论

I have a table list with three columns. There are the possibility to sort all columns up an down. When you click on the -Tag then the list will sorted but I'm getting the error message:

Error: $injector:unpr Unknown Provider

Unknown provider: orderbyFilterProvider <-

Here is the Ctrl:

var orderby = $filter('orderby');

$scope.sortType = '-maxAge';
$scope.sortReverse = false;

$scope.order = function (sortType, sortReverse) {
   $scope.nameslist = orderby($scope.nameslist, sortType, sortReverse);
};

The view (header):

...
<th>
  <a href="" ng-click="sortReverse = !sortReverse; order('fname',reverse)">
     Firstame
     <span ng-show="sortType=='fname' && !sortReverse" class="glyphicon glyphicon-triangle-bottom"></span>
     <span ng-show="sortType=='fname' && sortReverse" class="glyphicon glyphicon-triangle-top"></span>
  </a>
</th>
...

The view (table list):

<tr ng-repeat="item in filteredNames = (nameslist | orderBy: sortType:sortReverse)" class="show-cursor">
   <td>{{ item.fname }}</td>
   ...
</tr>

I don't know where is the problem?!

I have a table list with three columns. There are the possibility to sort all columns up an down. When you click on the -Tag then the list will sorted but I'm getting the error message:

Error: $injector:unpr Unknown Provider

Unknown provider: orderbyFilterProvider <-

Here is the Ctrl:

var orderby = $filter('orderby');

$scope.sortType = '-maxAge';
$scope.sortReverse = false;

$scope.order = function (sortType, sortReverse) {
   $scope.nameslist = orderby($scope.nameslist, sortType, sortReverse);
};

The view (header):

...
<th>
  <a href="" ng-click="sortReverse = !sortReverse; order('fname',reverse)">
     Firstame
     <span ng-show="sortType=='fname' && !sortReverse" class="glyphicon glyphicon-triangle-bottom"></span>
     <span ng-show="sortType=='fname' && sortReverse" class="glyphicon glyphicon-triangle-top"></span>
  </a>
</th>
...

The view (table list):

<tr ng-repeat="item in filteredNames = (nameslist | orderBy: sortType:sortReverse)" class="show-cursor">
   <td>{{ item.fname }}</td>
   ...
</tr>

I don't know where is the problem?!

Share Improve this question asked Jul 3, 2015 at 12:57 yuroyuro 2,2296 gold badges43 silver badges79 bronze badges 1
  • Can you give js fiddle link here . Then we can decide what is the problem in easiest way. – Amaranadh Meda Commented Jul 3, 2015 at 13:03
Add a ment  | 

1 Answer 1

Reset to default 10

You need to use camel case its orderBy not orderby in your controller

var orderBy = $filter('orderBy');
发布评论

评论列表(0)

  1. 暂无评论