S
S
Seva2015-08-01 14:15:42
Angular
Seva, 2015-08-01 14:15:42

Angular, orderBy and one dimensional array?

Good afternoon,
I know that the orderBy filter can sort associative arrays, but how to sort alphabetically a one-dimensional array like ['Vasya', 'Petya', 'Anya'] ?

...ng-repeat="name in names | orderBy: 'что написать тут?'">

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-08-01
Protko @Fesor

stop trying to do everything in html markup.

function MyController (names) {
    this.names = names.sort();
}

<ul ng-controller="MyController as my">
   <li ng-repeat="name in my.names">{{name}}</li>
</ul>

R
Roman Rakzin, 2015-08-01
@TwoRS

So what's the problem? Well, you wrote... Let's say there is a FIO field, then add
ng-repeat="name in my.names | orderBy: 'FIO'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question