It may help "How to write countdown code in AngularJS"
Step 1: HTML Sample Code
<div ng-app ng-controller="ExampleCtrl"> <div ng-show="countDown_text > 0">Your password is expired in 180 Seconds.</div> <div ng-show="countDown_text > 0">Seconds left {{countDown_text}}</div> <div ng-show="countDown_text == 0">Your password is expired!.</div> </div>
Step 2: Sample AngulaJs Code
function ExampleCtrl($scope, $timeout) { var countDowner, countDown = 10; countDowner = function() { if (countDown < 0) { $("#warning").fadeOut(2000); countDown = 0; return; // quit } else { $scope.countDown_text = countDown; // update scope countDown--; // -1 $timeout(countDowner, 1000); // loop it again } }; $scope.countDown_text = countDown; countDowner() }
A complete example of countdown in AngularJs, as shown below.
<!DOCTYPE html> <html> <head> <title>AngularJS Example - Single Timer Example</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> <script> function ExampleCtrl($scope, $timeout) { var countDowner, countDown = 10; countDowner = function() { if (countDown < 0) { $("#warning").fadeOut(2000); countDown = 0; return; </script> </head> <body> <div ng-app ng-controller="ExampleCtrl"> <div ng-show="countDown_text > 0">Your password is expired in 180 Seconds.</div> <div ng-show="countDown_text > 0">Seconds left {{countDown_text}}</div> <div ng-show="countDown_text == 0">Your password is expired!.</div> </div> </body> </html>
Anil Singh Dec 20 '14 at 5:59 a.m. 2014-12-20 05:59
source share