0

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;
});
}

1 Answer 1

1

try to refresh details use $interval in your controller.

$interval(function() {
  $scope.detail = 'call your getData service here';
}, 1000);

ClientsApp.controller("DbController",['$scope','$http', $interval, function($scope,$http,$interval){
  ...
}
Sign up to request clarification or add additional context in comments.

7 Comments

$interval is an id?
This is Angular controller: var ClientsApp = angular.module('ClientsApp',[]); ClientsApp.controller("DbController",['$scope','$http', function($scope,$http){ // Function to get employee details from the database getInfo(); function getInfo(){ // Sending request to EmpDetails.php files $http.post('includes/assets/receptie_clienti/databaseFiles/get_clients.php').success(function(data){ // Stored the returned data into scope $scope.details = data; }); }
$interval is a angular service provider, like window.setInterval. you can inject it at your controller
I did it like this: var ClientsApp = angular.module('ClientsApp',[]); ClientsApp.controller("DbController",['$scope','$http','$interval', function($scope,$http,$interval){ $interval(function() { $scope.detail = 'includes/assets/receptie_clienti/databaseFiles/get_clients.php'; }, 1000); ... in my Angular js script.
Nothing happens after I adeed that code in angular script. No error in console.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.