Why not just do all of the hide/show logic in the ng-if i.e.
ng-if="show == 4 && $rootScope.detailsList1.length > 0"
This would cause the browser to not render the div unless both of those conditionals are true.
Just some random info about ng-if, ng-show and ng-hide that might be helpful as well.
ng-if will only add the html it is wrapped around to the DOM if it is true. If it is false, it removes the html completely. This means you won't be able to access any element in this block if the ng-if is false.
ng-show/ng-hide on the other hand will still create the html to be displayed in the DOM, it will just add ng-hide as a class when the element should be hidden. This allows the elements to still be accessed with JavaScript even though they aren't visible.
The above was a misunderstanding of the question, I will leave it as it may be helpful when dealing with ng-if, ng-show, and ng-hide.
After playing with your plunker, I was able to get it working, although I think you should definitely clean up your variables. Rather than using $rootScope.detailsList1 to keep track of the number of items in your array, you should just use $scope.details.length. It will be a lot cleaner, easier to read, and easier to maintain in the future. Also, I'm not sure if they are bugs or intentional, but you have 3 different lists, all seemingly for the same thing, $rootScope.detailsList1, $scope.details, and $rootScope.detailsList. From just the snippet in plunker, I would assume all 3 of these should reference the same array, and none of it should be on the rootScope. If you need to pass it between controllers you would be better served using a service.
Having said that, to fix your current code base, just add this check to the end of the interval function
$interval(function() {
if ($scope.show === 4) {
if ($rootScope.detailsList <= $rootScope.detailsList1-1) {
++$rootScope.detailsList;
} else {
$rootScope.detailsList = 0;
$scope.show = 1;
}
}
else if ($scope.show < 4) {
++$scope.show;
} else {
$scope.show = 1;
}
// if the details list is empty and show is 4, skip back to 1
if ($rootScope.detailsList === 0 && $scope.show === 4) {
$scope.show = 1;
}
}, 5000, 0);