I have a scenario where i need to show a div when the timer total value is < 0 Here is the directive code:
angular.module('iSourcingApp.tpModule')
.directive('stopWatch', function($state) {
return {
restrict: 'A',
replace: false,
scope: {
name: "=",
timeOfInterview: "=",
onSend: '&',
startInterview: '&',
viewPage: "="
},
controller: function($scope, $rootScope, $interval) {
debugger
$rootScope.showDiv = {};
$scope.getTimeRemaining = function(endtime) {
$scope.t[$scope.name].total = Date.parse(endtime) - Date.parse(new Date());
$scope.t[$scope.name].seconds = Math.floor(($scope.t[$scope.name].total / 1000) % 60);
$scope.t[$scope.name].minutes = Math.floor(($scope.t[$scope.name].total / 1000 / 60) % 60);
$scope.t[$scope.name].hours = Math.floor(($scope.t[$scope.name].total / (1000 * 60 * 60)) % 24);
$scope.t[$scope.name].days = Math.floor($scope.t[$scope.name].total / (1000 * 60 * 60 * 24));
}
$scope.initializeClock = function(endtime) {
debugger
$scope.t = {};
$scope.t[$scope.name] = {};
$scope.updateClock = function() {
debugger
$scope.getTimeRemaining(endtime);
$scope.t[$scope.name].hours = ('0' + $scope.t[$scope.name].hours).slice(-2);
$scope.t[$scope.name].minutes = ('0' + $scope.t[$scope.name].minutes).slice(-2);
$scope.t[$scope.name].seconds = ('0' + $scope.t[$scope.name].seconds).slice(-2);
if ($scope.t[$scope.name].total == 0) {
console.log($scope.t[$scope.name].total);
$interval.cancel($scope.timeinterval);
$rootScope.showDiv[$scope.name] = true;
alert("Start interview for " + $scope.name);
} else {
if ($scope.t[$scope.name].total < 0) {
$interval.cancel($scope.timeinterval);
$rootScope.showDiv[$scope.name] = true;
}
}
}
$scope.updateClock();
$scope.timeinterval = $interval($scope.updateClock, 1000);
}
$scope.initializeClock($scope.timeOfInterview);
},
templateUrl: function() {
var tpl = $state.current.name;
return './tpModule/views/' + tpl + '.html';
}
};
});
Here if $scope.t[$scope.name].total < 0
then i am setting showDiv
to true
and when it is true i m showing a div
<div ng-show="showDiv[candidateInfo.name]" class="col-xs-offset-4 showDiv">
<p class="timer-text">The interview for {{candidateInfo.name}} has crossed scheduled time</p>
<div class="row showDiv" >
<a class="timer-text col-xs-3" style="cursor:pointer" ng-click="fnReschedule(candidateInfo.name, candidateInfo.recruiter)"><i >reschedule</i></a>
<a class="timer-text col-xs-3" style="cursor:pointer" ng-click="fnStartInterview(candidateInfo.name,candidateInfo.presentRound,candidateInfo.askedQuestions,candidateInfo._id,candidateInfo.dateOfInterview)"><i class="text-center">start interview</i></a>
</div>
</div>
So,what is happening here is initially some template is shown and after a sec or so the div is shown but i need not show the template initially if the timer is < 0
and the timer is different for different candidates
Any help would be appreciated.