我有以下Angular函数,可以通过$http
$interval
调用自动刷新视图中的数据
app.controller("processModel", function ($scope, $http, $interval) {
$scope.data
$scope.LoadData = function() {
$http({
method: "GET",
url: 'Home/DataRefresh',
params:{'_': +new Date() }
}).then(function success(response) {
$scope.data = response.data;
}, function error(errResponse) {
alert("data " + errResponse.data + " status " + errResponse.status + " headers " + errResponse.headers + "config " + errResponse.config + " statusText " + errResponse + " xhrStat " + errResponse.xhrStatus);
});
};
// Initial data load
$scope.LoadData();
// Refresh data on an interval
$interval($scope.LoadData, 10000);
});
调用它并使用以下HTML显示数据
<main class="container" role="main" ng-controller="processModel">
<div class="jumbotron">
<table>
<tbody>
<tr ng-repeat="item in data">
<td>{{item.info}}</td>
</tr>
</tbody>
</table>
</div>
</main>
我遇到的问题是,当每10秒调用一次Home / DataRefresh时,View只会将新(和重复)项添加到现有表的末尾而不是覆盖它。因此,它要么将新值附加到$scope.data
,要么不会自动重做由ng-repeat
构建的表格。
如何使用从Home / DataRefresh获取的新数据覆盖表的内容,我该怎么办?
答案 0 :(得分:0)
这是服务器端代码的问题,它在对数据库进行新的Get调用时没有清除缓存。角度工作正常。