angular.module('M12', ['ng']). controller('C12', function($scope, $interval){ $scope.num = 1; $scope.pro = function(){ $interval.cancel(t); $scope.num > 1 ? $scope.num-- : $scope.num = 5; } $scope.next = function(){ $interval.cancel(t); $scope.num < 5 ? $scope.num++ : $scope.num = 1; } let t = $interval(function(){ $scope.num < 5 ? $scope.num++ : $scope.num = 1; }, 1000) })