Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do orderby with angularJS for string array not object array

i have an string array in angularJS and i want to do some kind of sort for it's element i try this code but it isn't work and i don't know why any one has any idea

<div id="cpntainer" data-ng-init="countries = ['Syria','Lebanon','Jordon','Egypt']">
    Country Name <br />
    <input type="text" data-ng-model="name" /> <br />
    <ul>
        <li data-ng-repeat="country in countries | filter:name | orderBy:country:false "> {{ country }} </li>
    </ul>
</div>
like image 252
Ahmad Alyan Avatar asked Feb 16 '23 06:02

Ahmad Alyan


1 Answers

You can use a function in the orderBy-clause like this:

<li data-ng-repeat="country in countries | filter:name | orderBy:'toString()'"> {{ country }}</li>
like image 193
DanEEStar Avatar answered Apr 25 '23 05:04

DanEEStar