Angularjs 如何正确使用Angular 1.7控制器中的$interval自动刷新视图中的数据?

Angularjs 如何正确使用Angular 1.7控制器中的$interval自动刷新视图中的数据?,angularjs,Angularjs,我正在尝试在Angular 1.6应用程序中自动刷新表格,方法是: function monitoringConfigurationCtrl($scope, $http,$interval){ $interval($http.get('/monitoringresults'). then(function(response) { $scope.monitoringResults = response.data; }),10000); ... ) 我在

我正在尝试在Angular 1.6应用程序中自动刷新表格,方法是:

function monitoringConfigurationCtrl($scope, $http,$interval){


    $interval($http.get('/monitoringresults').
    then(function(response) {
        $scope.monitoringResults = response.data;
    }),10000);
...
)
我在浏览器控制台中遇到此错误:

angular.js:13236 TypeError: f is not a function
    at r (angular.js:12053)
    at m.$eval (angular.js:16820)
    at m.$digest (angular.js:16636)
    at m.$apply (angular.js:16928)
    at angular.js:12043
html视图如下所示:

<div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>Resource</th>
                                <th>Monitoring Method</th>
                                <th>Monitoring Parameters</th>
                                <th>Last Probed</th>
                                <th>Result</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr ng-repeat="result in monitoringResults">
                                <td>{{ result.monitoring_target }}</td>
                                <td>{{ result.monitoring_method }}</td>
                                <td>{{ result.monitoring_parameter }}</td>
                                <td>{{ result.date_recorded }}</td>
                                <td>{{ result.monitoring_result }}</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

资源
监测方法
监测参数
最后探测
结果
{{result.monitoring_target}
{{result.monitoring_method}}
{{result.monitoring_parameter}}
{{result.date_recorded}
{{result.monitoring_result}

使用Angular 1.X实现实时刷新的正确方法是什么?

这看起来只是一个语法错误。问题是您实际上是在
$interval
的参数中调用函数,而不是传递函数引用

如果您只是将调用包装在函数中,它应该可以工作:

$interval(function () {
  $http.get('/monitoringresults').
    then(function(response) {
        $scope.monitoringResults = response.data;
    });
}),10000);