It’s very simple, I only put the key code
<p ng-controller="myCtrl">
<input type="text" ng-model="clock.now"></p>
function myCtrl($scope,$timeout){
$scope.clock = {
now : new Date()
}
var updateClock = function(){
$scope.clock.now = new Date() ;
}
//$timeout(function(){
setInterval(function(){
updateClock()
$scope.$apply()
},1000)
updateClock();
}
You can use setInterval, but not $timeout. Why?
ringa_lee2017-05-15 16:51:56
Uh, $timeout
和 setInterval
可不是一对儿呀,你要用也得用 $interval
才是……;$timeout
是对 setTimeout
encapsulation.