我想反转一个数组。
<ul>
<li ng-repeat="todo in todos track by $index | reverse"><input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span></li>
</ul>
和 JS
var myfirstApp = angular.module('myfirstApp', []);
myfirstApp.filter('reverse', function() {
return function(items) {
return items.slice().reverse();
};
});
在我的 Controller 中我有
$scope.todos = [
{text: 'Learn AngularJS', done:false},
{text: 'Build an app', done:false}
];
但我得到“错误:items.slice 不是一个函数”,如果我删除幻灯片,我得到相同的反向。它读取数组的方式有问题吗?
最佳答案
更改 ng-repeat 的代码
todo in todos | reverse track by $index
关于javascript - Angularjs 反转数组给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26036200/