2
我有一個函數getData,它只是遞增var計數器的值。如何在控制器中更改值時更新DOM
每當增量發生,我想一定角度會自動更新一個div
裏面我已經試過NG綁定,但如果我點擊一個表單元素上它纔會起作用。
enquire.controller('DisplayEnquiries', function($scope){
$scope.getData = function(){
console.log('Run ' + $scope.counter);
$scope.counter;
if($scope.counter == undefined || $scope.counter == null){
$scope.counter = 1
$scope.counter++;
}
else{
$scope.counter++;
}
console.log('Execute ' + $scope.counter);
$scope.count = $scope.counter;
}
setInterval($scope.getData, 1000);
});
HTML
<div class="col-sm-5" ng-controller="DisplayEnquiries">
<h4>Unread User Queries</h4>
<p>
Count : <span ng-bind="count"></span>
</p>
</div>