Here is the code which is not working: 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']; });
An orderBy Filter in AngularJS is used to sort the given array to the specific order.
Definition and Usage The orderBy filter allows us to sort an array. By default, strings are sorted alphabetically, and numbers are sorted numerically.
You can order by a method, so you can use the toString method
<ul ng-repeat="strVal in arrVal | orderBy:'toString()' | filter:searchText">
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With