angularjs make a simple countdown

后端 未结 10 1545
别跟我提以往
别跟我提以往 2020-12-12 19:26

I would like make a countDown with Angular js. this is my code:

Html File

{{countDown}}
10条回答
  •  既然无缘
    2020-12-12 19:57

    The way I did , it works!

    • *angular version 1.5.8 and above.

    Angular code

    var app = angular.module('counter', []);
    
    app.controller('MainCtrl', function($scope, $interval) {
      var decreamentCountdown = function() {
        $scope.countdown -= 1;
        if ($scope.countdown < 1) {
          $scope.message = "timed out";
        }
      };
      var startCountDown = function() {
        $interval(decreamentCountdown, 1000, $scope.countdown)
      };
      $scope.countdown = 100;
      startCountDown();
    });
    
    
    
    
    
      {{countdown}} {{message}}
    

提交回复
热议问题