I would like make a countDown with Angular js. this is my code:
Html File
<div ng-app ng-controller = "countController"> {{countDown}} <div>
js File
function countController($scope){
$scope.countDown = 10;
var timer = setInterval(function(){$scope.countDown--; console.log($scope.countDown)},1000);
}
in console.log it works I have a countdown but in {{countdown}} refresh it doesn't could you help me please? thanks!
As of version 1.3 there's a service in module ng:
$interval
Use with caution:
From: Angular's official documentation.
Please take a look at this example here. It is a simple example of a count up! Which I think you could easily modify to create a count down.
http://jsfiddle.net/ganarajpr/LQGE2/
JavaScript code:
HTML markup:
It might help to "How to write the code for countdown watch in AngularJS"
Step 1 : HTML Code-sample
Step 2 : The AngulaJs code-sample
The full example over countdown watch in AngularJs as given below.
The way I did , it works!
Angular code
Html View Code.
You probably didn't declare your module correctly, or you put the function before the module is declared (safe rule is to put angular module after the body, once all the page is loaded). Since you're using angularjs, then you should use $interval (angularjs equivalence to setInterval which is a windows service).
Here is a working solution:
Note: it stops at 0 in the html view, but at 1 in the console.log, can you figure out why? ;)