angular 每 15 秒自动刷新一次范围
Auto refresh scope every 15 sec with angular
我的代码需要帮助,我想刷新列表范围而不刷新页面,只是范围,我需要每 15 秒刷新一次,有人可以帮我吗?
$scope.getAllTickets = function () {
$scope.listAllTickets = [];
$timeout(function () {
$.ajax({
url: '/Chamados/GetAllTickets',
type: 'POST',
success: function (result) {
$scope.listAllTickets = result;
$scope.$apply();
},
error: function (xhr, status) {
toastr.error("Ocorreu um erro ao carregar os dados.", "Tickets");
}
});
},
500);
}
所以我想出了如何去做,如果有人需要解决像我这样的问题,我会把代码留在这里
function refreshScope() {
timer = setTimeout(function () {
$scope.getAllTickets();
$scope.$apply();
}, 15000);
}
下面的代码会给你想要的结果。
$scope.getAllTickets = function () {
$scope.listAllTickets = [];
var func = function () {
$.ajax({
url: '/Chamados/GetAllTickets',
type: 'POST',
success: function (result) {
$scope.listAllTickets = result;
$scope.$apply();
},
error: function (xhr, status) {
toastr.error("Ocorreu um erro ao carregar os dados.", "Tickets");
}
});
};
$interval(func, 15000);
}
我的代码需要帮助,我想刷新列表范围而不刷新页面,只是范围,我需要每 15 秒刷新一次,有人可以帮我吗?
$scope.getAllTickets = function () {
$scope.listAllTickets = [];
$timeout(function () {
$.ajax({
url: '/Chamados/GetAllTickets',
type: 'POST',
success: function (result) {
$scope.listAllTickets = result;
$scope.$apply();
},
error: function (xhr, status) {
toastr.error("Ocorreu um erro ao carregar os dados.", "Tickets");
}
});
},
500);
}
所以我想出了如何去做,如果有人需要解决像我这样的问题,我会把代码留在这里
function refreshScope() {
timer = setTimeout(function () {
$scope.getAllTickets();
$scope.$apply();
}, 15000);
}
下面的代码会给你想要的结果。
$scope.getAllTickets = function () {
$scope.listAllTickets = [];
var func = function () {
$.ajax({
url: '/Chamados/GetAllTickets',
type: 'POST',
success: function (result) {
$scope.listAllTickets = result;
$scope.$apply();
},
error: function (xhr, status) {
toastr.error("Ocorreu um erro ao carregar os dados.", "Tickets");
}
});
};
$interval(func, 15000);
}