-1

I'm fetching data from api and populating in the table i need to relaod the table only in every 1 second , i tried using $timeout but im getting error saying -

  $scope.tableParams.reload();//TypeError: Cannot read property 'reload' of undefined

code

    <div align="center">
        <div ng-app="myApp" ng-controller="customersCtrl">
            <table ng-table="tableParams">
                <tr>
                    <td>device id</td>
                    <td>device unique id</td>
                    <td>access status</td>
                    <td>current time</td>
                </tr>
                <tr>
                    <td>{{ access.id }}</td>
                    <td>{{ access.devid }}</td>
                    <td><img ng-src="{{statusValues[access.status]}}" /></td>
                    <td>{{ access.CurrentTime }}</td>
                </tr>
            </table>
        </div>
        </div>



      <script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('customersCtrl', function ($scope, $http, $timeout) {
    $http.get("http://example.com/get")
    $scope.reloadTable = function () {
        $timeout(function () {
            $scope.tableParams.settings().$scope = $scope;
            $scope.tableParams.reload();
            $scope.reloadTable();
        }, 1000)
    };
    $scope.reloadTable();
});
        </script>
Swapna
  • 403
  • 3
  • 6
  • 24

3 Answers3

1

just add the following code line into my code after tableParams instance creation.

$scope.tableParams.settings().$scope = $scope;
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
1

Hi Your trying to reload the params using reload method, but it seems that reload() method is working with $route concept to update the url, based on params. and insted of $timeout , try with $interval,

I've done some modification here, Plesae take a look and This may helpful

var app = angular.module('myApp', []);
app.controller('customersCtrl', function ($scope, $http, $interval) {
  $scope.fn = function(){
    $http.get("https://jsonplaceholder.typicode.com/posts")
      .then(function(data){
      console.log(data.data)
        $scope.Tdata = data.data;      
    })
    }
        $interval(function () {          
          $scope.fn()
        }, 1000)      
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp' ng-controller="customersCtrl">
<div align="center">
        <div ng-app="myApp" ng-controller="customersCtrl">
            <table ng-table="tableParams">
                <tr>
                    <td>device id</td>
                    <td>device unique id</td>
                    <td>access status</td>
                    <td>current time</td>
                </tr>
                <tr ng-repeat="d in Tdata">
                    <td>{{ d.id }}</td>
                    <td>{{ d.title }}</td>
                    <td><img ng-src="{{}}" /></td>
                    <td>{{ d.body }}</td>
                </tr>
            </table>
        </div>
        </div>
</div>
1
<script type="text/javascript">
        var app = angular.module('myApp', []);
        app.controller('customersCtrl', function ($scope, $http, $timeout, $interval) {
            getData = function(){
                $http.get("http://example.com/get")
                    .success(function(data) {
                        $scope.tableParams.settings().$scope = $scope;
                        $scope.reloadTable();
                    })
                    .error(function(data, status) {
                        console.error(status);
                    })
            }

            $interval(function (){
                getData();
            }, 1000);
</script>
MGA
  • 511
  • 2
  • 11
  • can u put in the script tag ? – Swapna Jan 25 '17 at 07:27
  • can you please put your working code in https://jsfiddle.net/ so we can do edit there as we are just giving you idea to follow not exactly writing your code here. – MGA Jan 25 '17 at 07:39
  • shared code in jsfiddle https://jsfiddle.net/7kexryjc/1/ getting settings not defined error – Swapna Jan 25 '17 at 07:47