【发布时间】:2016-05-11 06:49:12
【问题描述】:
我在客户端有一个带有角度 js 和 html 的 spring 应用程序,我想每 6 秒更新一次视图中的信息,因为我调用了 setInterval 函数,但它不会改变视图 这是我的代码
$scope.aat=function(){
$http.get("http://localhost:8080/projet/getInspectionEnCoursDinspection")
.success(function (data) {
$scope.tab1=data;
console.log("size="+ $scope.inspectionEnCoursDinspection1.length);
})
} ,
setInterval(function(){ $scope.aat() },60000);
这是我的html视图
<table class="table table-bordered">
<tr ng-repeat="insp in tab1">
<td>Mat{{insp.vehicule.matricule}}
<div ng-repeat="aa in insp.tests">
Test<ul><li ng-repeat="defaut in aa.defauts">{{defaut.nomDefaut}}</li></ul>
</div>
</td>
<td><button ng-click="annulerTest()"
class="btn btn-default btnt">
<i class="glyphicon glyphicon-remove"></i>
</button></td>
</tr>
</table>
任何帮助将不胜感激
【问题讨论】:
-
60000ms 是每分钟,而不是每 6 秒。
-
尝试使用
$scope.apply到$scope.aat告诉 Angular 将更改注册到您的数组。 -
好的,谢谢@Bergi,但这不是问题,视图不会改变,只是我刷新了页面
-
$scope.aat=function(){ $http.get("http://localhost:8080/projet/getInspectionEnCoursDinspection") .success(function (data) { $scope.tab1=data; console.log("size="+ $scope.inspectionEnCoursDinspection1.length); $scope.apply(); }) } -
你应该尝试使用 Angular 的 $interval 而不是 plainJS 'SetInterval'。除非您手动
$scope.apply()
标签: javascript angularjs