我有一个页面加载时调用的api。来自api的数据通过角度重复加载到表格中。我也有一个JavaScript函数每10秒调用一次,调用同一个数据集的api。我想知道如何将新数据集应用到表中,并在数据集更改时替换旧数据,以及如何使用动画直观显示此更改。代码如下。角度表刷新
表代码
<body ng-app="myApp" ng-controller="ScansController">
<div class="bs-example" id="scan-table">
<table id="scansTable" class="table table-striped">
<thead>
<tr>
<th>ScanId</th>
<th>First Name</th>
<th>Last Name</th>
<th>Time Stamp</th>
</tr>
<tr ng-repeat="scan in Scans">
<td>
{{scan.scanId}}
</td>
<td>
{{scan.firstName}}
</td>
<td>
{{scan.lastName}}
</td>
<td>
{{scan.timeStamp}}
</td>
</tr>
</thead>
</table>
</div>
javascipt的间隔码
<script>
window.setInterval(function() {
$.ajax({
url: 'api/scans/',
type: 'Get',
dataType: 'json',
success: function (data) {
//Something here
},
error: function() {
alert("something failed");
}
});
}, 10000);
</script>
角代码
var myApp = angular.module('myApp', []);
myApp.service('dataService', function ($http) {
this.getData = function() {
return $http({
method: 'GET',
url: '/api/scans/'
});
}
});
myApp.controller('ScansController', function ($scope, dataService) {
$scope.Scans = [];
dataService.getData().then(function (result) {
$scope.Scans = result.data;
console.log(result.data);
});
});
当在该模型中的更改会自动对视图中右键影响? Angular会照顾那个吗? https://jsfiddle.net/eu81273/pPU4m/ 看到这个链接 –