尝试使用 Angular 中的 $interval 来使用 ng-show 更改列表中当前可见的项目。检查 html,我注意到角度将 ng-show 从 true/false 更改,但它并没有删除 ng-hide 类。
html 很简单:
<h1>Hello Plunker!</h1>
<div ng-controller="MyCtrl">
<div>Iterator: {{i}}</div>
<ul>
<li ng-repeat="d in data" ng-show="{{i == $index}}">{{i}} - {{$index}} - {{d}}</li>
</ul>
</div>
app.js 也很基本:
(function(){
var app = angular.module('MyApp', ['my-controller']);
})();
和我的模块/控制器
(function(){
var app = angular.module('my-controller', []);
app.controller('MyCtrl', ['$scope', '$interval', function($scope, $interval){
$scope.data = [111, 222, 333, 444];
$scope.i = 0;
var timeoutId;
timeoutId = $interval(function(){
$scope.i ++;
if ($scope.i >= $scope.data.length)
$scope.i = 0;
},
1000);
}]);
})();
这是我的 plnkr http://plnkr.co/edit/tdz1ejGK5qXLJy4nqPRG?p=preview