javascript - $数据刷新超时服务不起作用(Angularjs)

标签 javascript angularjs

所以我一直在使用 angularjs 和 symfony 开发一个应用程序。我试图每 5000 毫秒重复检索一次数据,因此我采用“$timeout”功能从服务器获取实时数据检索。

这是我的 Controller 代码:

.controller('clientController', [ '$rootScope','$scope', 'Api' , 'toastr',   
'$window', '$routeParams', '$filter'  , '$timeout',
 function($rootScope,$scope, Api  ,toastr, $window, $routeParams, $filter , 
 $timeout) {

     $rootScope.myVar=true;


 $scope.clients = [];
 var  retrieveItems = function () {

 Api.getAllClients()
  .then(function (result) {
    console.log('result', result);
    $scope.clients = result.data;
    $timeout(retrieveItems, 5000);
  }, function (error) {
    console.log('error', error);
  });
  };



 ...

}])

这是 vue 代码:

 <table class="table table-striped table-bordered" id="editable-datatable">
                           <thead>
                                <tr>
                                    <th>Username</th>
                                    <th>Email</th>
                                     <th>tel</th>
                                     <th>Actions</th>

                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="client in clients" id="1" class="gradeX">
                                    <td>{{client.username}}</td>
                                    <td>{{client.email}}</td>
                                   <td>{{client.tel}}</td>

                                     <td  collapse=3>

                                                 <a style="border: 1px solid rgba(10, 6, 6, 0.25); padding: 4px;" ng-href="#!/client/{{client.id}}" ng-click="ClientDetailsController()">
                                                   <i class="icon-eye-open"></i> Details 
         </a> &nbsp;&nbsp;



<span style="margin-left: 10px"><a  data-toggle="modal" href  data 
target="#exampleModal" ng-click="setID(client.id)" >
                       <i class="icon-remove-sign"></i> Delete
                                                  </a></span>

                                        </td>


                                </tr>


                            </tbody>

                        </table>

我的问题是,每当我删除“retrieveItems”功能时,一切都会正常工作。我得到了所有客户端,但何时添加超时服务,以便我可以每 5 秒刷新一次注册的客户端...客户端不会在 vue 上加载,但错误部分中没有错误。有人请告诉我问题到底是什么......任何其他建议可以使实时检索发挥作用。提前致谢 。

最佳答案

要每 5000 毫秒获取一次数据,您应该使用

$interval service $interval

关于javascript - $数据刷新超时服务不起作用(Angularjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46616962/

相关文章:

JavaScript 自动 POST 和 NAME

css - 没有不必要的东西的 Twitter Bootstrap AngularJS UI

AngularJS 强制应用程序从特定 URL 启动

angularjs - 如何使用 ng-repeat 创建用户定义的过滤器

ruby-on-rails - AngularJS错误: [$injector:nomod] when trying to load 'templates'

javascript - 如何在 JavaScript 中从字符串解析数组?

javascript - 不再需要在 React 组件类中绑定(bind)函数了吗?

javascript - 我想随机显示 div - 我该怎么做?

javascript - 我正在尝试使用带有 express 的 Sequelize 发布请求来更新 mySQL 数据库

javascript - AngularJS 工厂依赖项