I have a table which shows values from db through AngularJS:
<div class="container wrapper" ng-controller="DbController">
<table class="table table-hover">
<tr>
<th>NUMĂR ORDINE</th>
<th>NUME CLIENT</th>
<th>ACȚIUNE</th>
</tr>
<tr ng-repeat="detail in details| filter:search_query">
<td>{{detail.id}}</td>
<td>{{detail.nume_client}}</td>
<td>
<button class="btn btn-warning" ng-click="editInfo(detail)" title="Preiau client"><span class="glyphicon glyphicon-edit"></span></button>
</td>
</tr>
</table>
I can`t find a function that will refresh the table at a few seconds automatically, to reload the new data. Is there a way to do this without refreshing the page manually or clicking a button?
I have a function which refreshes a span but I don`t know how to adapt it to Angular:
<script type="text/javascript">
function refreshDiv()
{
$("#refresh").load("includes/assets/receptie_clienti/databaseFiles/get_client_count.php");
}
window.setInterval(refreshDiv, 1000);
</script>
And HTML:
<span id="refresh">0</span> //Initial value is 0 and it changes when new values are adeed to database
LE: Fixed like the answer selected:
Modified AngularJS Controller:
var ClientsApp = angular.module('ClientsApp',[]);
ClientsApp.controller("DbController",['$scope','$http','$interval', function($scope,$http,$interval){
// Refresh the data automatically to get clients details from the database
$interval(callAtInterval, 1000);
function callAtInterval() {
$http.post('includes/assets/receptie_clienti/databaseFiles/get_clients.php').success(function(data){
// Stored the returned data into scope
$scope.details = data;
});
}