这是我的代码,我不知道我在做什么错误???是否有内置的过滤器或函数来排序整数或数字的数组??
<body data-ng-app="app" data-ng-controller="controller1" >
<div class="container">
<div class="row">
<input type="text" ng-model="searchbox" />
<li ng-repeat="num in numbers|filter:searchbox|orderBy:number">
{{num}}
</li>
</div>
</div>
<script type="text/javascript">
var app=angular.module('app', []).controller('controller1', ['$scope', function($scope){
$scope.numbers=[10,8,6,7];
$scope.number=function(data)
{
return data.sort();
}
}
]);
</script>
</body>
答案 0 :(得分:2)
查看此答案orderBy array item value in Angular ng-repeat
这意味着您可以执行以下操作:
app.controller('ctrl', ['$scope', function($scope){
$scope.numbers = [10,8,6,7];
$scope.identity = angular.identity;
}]);
和
<li ng-repeat="num in numbers | orderBy:identity">
{{num}}
</li>