这是我原来的plunker演示http://plnkr.co/edit/9UBZ9E4uxAo1TXXghm1T?p=preview。
对于div 4(ng-if =“show == 4”)当列表为空时我想隐藏特定的div,当前每个div显示的间隔为5秒,任何输入?我们正在显示每个div基于$ interval,需要修改js代码以隐藏div detailsList==0
。
JS代码:
app.controller('MainController', function($scope, $rootScope, $interval) {
$scope.show = 1;
$rootScope.detailsList = 0;
$interval(function() {
if ($scope.show === 4) {
if ($rootScope.detailsList < 2) {
++$rootScope.detailsList;
} else {
$rootScope.detailsList = 0;
$scope.show = 1;
}
} else if ($scope.show < 4) {
++$scope.show;
} else {
$scope.show = 1;
}
}, 5000, 0);
});
答案 0 :(得分:0)
使用一个开始变量来控制$ interval,例如如下所述
$scope.start = 1 ; // 1 to start and 0 to stop
使用上述启动变量
更新了控制器登录app.controller('MainController', function($scope,$rootScope, $interval) {
$scope.show = 1;
$rootScope.detailsList = 0;
$scope.start = 1;
var intervalPromise = $interval(function() {
if($scope.start ==1){
if ($scope.show === 4) {
if ($rootScope.detailsList < 2) {
++$rootScope.detailsList;
} else {
$rootScope.detailsList = 0;
$scope.show = 1;
$scope.start =0;
}
}
else if ($scope.show < 4) {
++$scope.show;
} else {
$scope.show = 1;
}
}
}, 1000, 0);
});
答案 1 :(得分:0)
ABC12345-1
ABC12345-2
ABC12345-3
条件显示你的div。
而是使用另一个变量来显示div标签:
我通过添加新变量show==4
更改了控制器:
Coontroller:
showDivFour
你的HTML:
改变:
app.controller('MainController', function($scope,$rootScope, $interval) {
$scope.show = 1;
$rootScope.detailsList = 0;
$scope.showDivfour = false;
$interval(function() {
if ($scope.show === 4) {
if ($rootScope.detailsList < 2) {
++$rootScope.detailsList;
} else {
$rootScope.detailsList = 0;
$scope.show = 1;
}
if($rootScope.detailsList!=0){
$scope.showDivenfour = true;
}else{
$scope.showDivenfour = false;
}
}
else if ($scope.show < 4) {
++$scope.show;
} else {
$scope.show = 1;
}
}, 5000, 0);
});