我怎么能编制实时计时器倒计时?

时间:2014-08-28 09:40:36

标签: angularjs countdowntimer

我已经完成了AngularJS计时器倒计时,但是当页面重新加载倒计时重新开始时。我的目标是在重新加载页面后倒计时倒计时。 谢谢!

这里有我的代码 - >

HTML:

<div ng-app="timerApp" ng-controller="TimeControll">
    <timer autostart="false" interval="1000" countdown="345600">{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds.</timer>
    <button ng-click="startTimer()" ng-disabled="timerRunning">Start Timer</button>
    <button ng-click="stopTimer()" ng-disabled="!timerRunning">Stop Timer</button>
</div>

Angular JS:

<script type="text/javascript">
    var eventApp = angular.module('timerApp', ['timer'], function($interpolateProvider) {
        $interpolateProvider.startSymbol('[[');
        $interpolateProvider.endSymbol(']]');
    });
    function TimeControll($scope, $http) {
        $scope.timerRunning = false;

        $scope.startTimer = function (){
            $scope.$broadcast('timer-start');
            $scope.timerRunning = true;
        };

        $scope.stopTimer = function (){
            $scope.$broadcast('timer-stop');
            $scope.timerRunning = false;

        };

        $scope.$on('timer-stopped', function (event, data){
            console.log('Timer Stopped - data = ', data);
        });

    }
    TimeControll.$inject = ['$scope'];
</script>

0 个答案:

没有答案