I have a model that contains a list of countries
$scope.model = {
name: "foo",
countriesVisited: ["CA", "AR", "GB", "FR", "MX", "AU", "IE", "RU", "IT", "ES", "IN", "US", "NL", "DE", "CL", "BR", "JP", "NZ", "PL"]
}
Using an ng-repeat directive lists them in the order they are shown. Putting an orderBy filter does order the items, but the order is seemingly random. See this plunker
Remove the filter and watch the output shift. Paste it back and it's in a weird order.
Is there a way to get the countriesVisited array to order without moving it to it's own $scope variable?
<li ng-repeat="country in model.countriesVisited | orderBy:'toString()'">
Change your orderBy to orderBy: 'toString()'. Primitives don't sort by default, but you can pass in a function as we are doing here.
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