AngularJs を使用してタイマーを作成しようとしましたが、setInterval メソッド内で timerCount をインクリメントすると、値は変更されますが、ビューは新しい値で更新されません。コンソール ログを確認したところ、timerCount が必要に応じて増加し、ボタンをもう一度クリックすると、timerCount がビューの現在の値を取得することがわかりました。ビューを毎秒変更するにはどうすればよいですか?
ここにhtmlがあります:
<p>timer count: {{timerCount}}</p>
<button ng-click="startTimer()">start timer</button>
そしてコントローラー:
var app=angular.module('examApp',[]);
app.controller('examCtrl',function($scope){
$scope.timerCount=0;
$scope.startTimer=function(){
setInterval(function(){
console.log($scope.timerCount);
$scope.timerCount++;
},1000)
}
})