I'm learning AngularJS and as an exercise trying to write an ascending sort filter:
This is my html file:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../Scripts/angular.min.js"></script>
<script src="../Scripts/Controllers/app.js"></script>
</head>
<body ng-app="myApp">
<ul ng-init="names = ['Peter','Anton','John']">
<li ng-repeat="name in names | sortAscending ">
<span>{{name}}</span>
</li>
</ul>
</body>
</html>
This is my filter:
app.filter("sortAscending", function () {
return function (input) {
var result = [];
for (var i = 0; i < input.length; i++) {
if (input[i] > input[i + 1]) {
result.push(input[i]);
}
}
return result;
}
});
I thing something is wrong in the loop regarding comparing the values.
What am I doing wrong?