我有一个表格,通过AngularJS显示db的值:
<div class="container wrapper" ng-controller="DbController">
<table class="table table-hover">
<tr>
<th>NUMĂR ORDINE</th>
<th>NUME CLIENT</th>
<th>ACȚIUNE</th>
</tr>
<tr ng-repeat="detail in details| filter:search_query">
<td>{{detail.id}}</td>
<td>{{detail.nume_client}}</td>
<td>
<button class="btn btn-warning" ng-click="editInfo(detail)" title="Preiau client"><span class="glyphicon glyphicon-edit"></span></button>
</td>
</tr>
</table>
我找不到一个会在几秒钟后自动刷新表的函数,以重新加载新数据。有没有办法在不手动刷新页面或单击按钮的情况下执行此操作?
我有一个刷新跨度的功能,但我不知道如何使它适应Angular:
<script type="text/javascript">
function refreshDiv()
{
$("#refresh").load("includes/assets/receptie_clienti/databaseFiles/get_client_count.php");
}
window.setInterval(refreshDiv, 1000);
</script>
和HTML:
<span id="refresh">0</span>
//初始值为0,当新值适用于数据库时,它会发生变化
LE:修正了所选的答案:
修改后的AngularJS控制器:
var ClientsApp = angular.module('ClientsApp',[]);
ClientsApp.controller("DbController",['$scope','$http','$interval', function($scope,$http,$interval){
// Refresh the data automatically to get clients details from the database
$interval(callAtInterval, 1000);
function callAtInterval() {
$http.post('includes/assets/receptie_clienti/databaseFiles/get_clients.php').success(function(data){
// Stored the returned data into scope
$scope.details = data;
});
}
答案 0 :(得分:1)
尝试使用控制器中的$ interval刷新详细信息。
var a uint64 = 0
const N = 10 * 1024 * 1024
var data [N]uint64
func main() {
for i := 0; i < 16; i ++ {
go func(id int) {
source := rand.NewSource(int64(id))
local_rand := rand.New(source)
for {
data[local_rand.Int31n(N)] = uint64(1)
}
}(i)
}
for i := 0; i < 16; i++ {
go func() {
for {
atomic.AddUint64(&a, uint64(1))
}
}()
}
var b uint64 = 0
for {
c := atomic.LoadUint64(&a)
fmt.Println(c - b)
b = c
time.Sleep(time.Second)
}
}