How to make orderby filter work in an array of strings?

Here is the code that does not work: Demo: http://jsfiddle.net/8dt94/63/

<div ng-controller="MyCtrl"> <input type="text" ng-model="searchText" /> <ul ng-repeat="strVal in arrVal|orderBy|filter:searchText" > <li>{{strVal}}</li> </ul> </div> var app=angular.module('myApp', []); app.controller('MyCtrl', function ($scope,$filter) { $scope.arrVal = ['one','two','three','four','five','six']; }); 
+82
angularjs
Jan 24 '13 at 2:49
source share
2 answers

You can order by method, so you can use toString method

 <ul ng-repeat="strVal in arrVal | orderBy:'toString()' | filter:searchText"> 
+238
Apr 7 '13 at 4:04
source share

Write a custom filter :

 app.filter('mySort', function() { return function(input) { return input.sort(); } }); 

HTML:

 <ul ng-repeat="strVal in arrVal|filter:searchText|mySort"> 

Fiddle

+11
Jan 24 '13 at 4:02
source share



All Articles