angularjs - Using $timeout within my app -


i'm using $timeout service , i'm wondering why 'mainctrl.date.raw' variable won't update every second. ideas?

angular.module('myapp', []) .controller('mainctrl', ['$timeout',function($timeout){     var mainctrl = this;     mainctrl.date = {};     $timeout(function(){         mainctrl.date.raw = new date();        }, 1000); }]); 

use $interval instead, since $timeout fire function once when timer finishes, , $interval fire function when counter finishes, , start again counter, until clear it.

angular.module('myapp', []) .controller('mainctrl', ['$interval',function($interval){     var mainctrl = this;     mainctrl.date = {};     $interval(function(){         mainctrl.date.raw = new date();        }, 1000); }]); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -