【发布时间】:2015-02-03 11:53:11
【问题描述】:
尝试使用 Angular 中的 $interval 来使用 ng-show 更改列表中当前可见的项目。检查 html,我注意到 ng-show 的角度从真/假发生了变化,但它并没有删除 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);
}]);
})();
【问题讨论】:
标签: javascript angularjs angularjs-scope angularjs-ng-repeat