Say I have an angular filter translate which does stuff on strings – doesn’t matter what – and a filter sort which sorts stuff alphabetically (as in orderBy : 'toString()').
I now want to print out strings from an array str of strings, but sorted according to their translation. That is, I want to make the following html code work:
<div ng-repeat="s in strs | translate | sort">{{ s }}</div>
It doesn’t work – I assume it’s because translate is a filter acting on strings, sort of like having signature String → String. But I need it to act on arrays of strings, right? Sort of like having signature [String] → [String], right? If that’s true, I need to find a way to map translate over arrays, such as strs, within that angular expression.
How can I do that or achieve what I want elegantly in the angular way?
Example. Say translate sends strings 'a', 'b', 'c' to 'z', 'y', 'x' respectively. I then want the angular-enhanced html element above to produce an equivalent html output to:
<div>c</div> <div>b</div> <div>a</div>
s in (strs | translate | sort)| orderBy: myFilter(), and inside your filter function justreturn $filter('translate')(string)