简体   繁体   English

计时器在0:0时发出警报消息

[英]alert message when timer at 0:0

I have a directive where i am calculating timer count down as below 我有一条指令,我正在计算计时器倒计时如下

<div stop-watch name="candidateInfo.name" time-of-interview="candidateInfo.dateOfInterview" class="stop-watch"></div>

    'use strict';
angular.module('iSourcingApp.tpModule')
    .directive('stopWatch', function($state) {
        return {
            restrict: 'A',
            replace: false,
            scope: {
                name: "=",
                timeOfInterview: "=",
                onSend: '&',
                startInterview:'&',
                viewPage:"="
            },
            controller: function($scope, $interval) {debugger
                $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() {
                        $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.timeOfInterview);
                        }
                    }
                    $scope.updateClock();
                    $scope.timeinterval = $interval($scope.updateClock, 1000);
                }
                $scope.initializeClock($scope.timeOfInterview);
            },
            templateUrl: function() {
                var tpl = $state.current.name;
                return './tpModule/views/' + tpl + '.html';
            }
        };
    });

but here i am unable to stop timer though count down reaches 0 但是在这里我无法停止计时器,尽管倒数达到0

Here the timeOfInterview is in ng-repeat and t[$scope.name] i am using to bind different timer to different candidates. 这里的timeOfInterview在ng-repeat和t[$scope.name]我正在将不同的计时器绑定到不同的候选项。

here is the below template example for binding 这是绑定的以下模板示例

<div ng-show="viewPage" class=" btn active interview-timer" ng-click="startInterview();onSend()">
<p>Interview Starts in
    <span class="days" ng-bind="t[name].days"></span>:
    <span class="hours" ng-bind="t[name].hours"></span>:
    <span class="minutes" ng-bind="t[name].minutes"></span>:
    <span class="seconds" ng-bind="t[name].seconds"></span>
</p>

Any help is appreciated. 任何帮助表示赞赏。

I think you should call 我想你应该打电话

$interval.cancel($scope.timeinterval);

instead of 代替

 $interval.cancel($scope.timeOfInterview);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM