app.controller('ExamCheckinCtrl', [ '$rootScope', '$scope', '$stateParams','$interval', function($rootScope, $scope, $stateParams, $interval) { $scope.waitNum=-1; $scope.inRoomFlag = true; $scope.openroom = function (){ $rootScope.ajaxRequest({ url : '../exam/online/meeting/url.htm', data : { agent_id : $stateParams.agent_id, aspect_id : $stateParams.aspect_id, std_id: $rootScope.ArtStdReg.std_id } }, function(response) { // alert(response.entity); window.location = response.entity; }); } $scope.inroom = function(){ $rootScope.ajaxRequest({ url : '../exam/online/wait/num.htm', data : { agent_id : $stateParams.agent_id, aspect_id : $stateParams.aspect_id, std_id: $rootScope.ArtStdReg.std_id } }, function(response) { $scope.waitNum=response.map.waitNum; // $scope.inRoomFlag = response.map.inRoomFlag; }); } $scope.inroom(); $scope.i=0; $scope.checkinroom = function(){ if ($scope.waitNum > 10) { if($scope.i++>=15){ $scope.i=0; $scope.inroom(); } } else $scope.inroom(); } var timer = setInterval(function() { $scope.$apply(function() { $scope.checkinroom(); }); }, 15000); $scope.$on('$destroy', function() { if (timer) { // clearInterval(timer); timer = null; } }); }])