ページ読み込み時に呼び出されるAPIがあります。 apiからのデータは、角度ng-repeatを介してテーブルにロードされます。私も同じデータセットの同じAPIを呼び出す10秒ごとに呼び出されるjavascript関数があります。新しいデータセットをテーブルに適用し、データセットが変更された場合は古いものを置き換え、アニメーションでこの変更を視覚的に表示する方法を知りたいと思います。コードは以下の通りです。角テーブルのリフレッシュ
表コード
<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);
});
});
モデルの変更があった場合には、自動的にビューの右に影響を与えるのだろうか?角度はそれを処理しますか? https://jsfiddle.net/eu81273/pPU4m/ このリンクを参照 –