I'm having some issues in my application where I'm using setInterval to poll my server every X seconds to check for new messages, when it finds them it adds them to the SQLite database on the application and updates the Object containing the data for displacement on the screen.
The issue is that the values don't update automatically, as you can see in an example provided through this snippet below. Just click the button and you'll notice really quickly t hat nothing is happening in either the ng-repeat or just the standard {{variable}} display.
Click the button again and all of a sudden you have some results, but they're inconsistent and explosive.
var app = angular.module('app', [])
.controller('Ctrl', function($scope) {
$scope.console = "";
$scope.arr = [];
$scope.init = function() {
setInterval(function() {
$scope.arr.push("Value");
}, 1000);
};
$scope.start = function() {
alert("Started");
$scope.init();
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<div ng-app="app" ng-controller="Ctrl">
<button ng-click="start()">Start Example</button>
<br>
<h5>For each:</h5>
<div id="repeat-container" ng-repeat="x in arr">
Value index: {{$index}}
<br>
</div>
<hr>Updating value of array: {{arr}}
<hr>
<h5>Console:</h5>
{{console}}
<div>
I'm personally working with ng-repeat trying to get these values to display properly when updated through setInterval. There's a custom debug console I added in there, considering console.log doesn't show anything on snippets (Unless it's in the debug window, which I haven't checked, because I'm an idiot).
Why aren't they updating? Usually Angular does a really good job at keeping everything on the page updated and in sync with the values in the scope.