Answer the question
In order to leave comments, you need to log in
How to update data in angular.js from php server?
Good afternoon, how to update data when developing on angular.js?
// контроллер, который должен обновляться,
// каждые n секунд, когда открыта страница с этим контроллером
.controller('AdminCtrl', function($scope, Factory) {
Factory.getReserv(function (results) {
$scope.resers = results;
})
})
//фактори
.factory('Factory', function($http) {
return {
getReserv: function(callback){
var url = 'url запроса';
$http.post(url).success(callback);
}
})
Answer the question
In order to leave comments, you need to log in
Instead of setInterval , it's better to use the $interval service. And then you have to stop the timer. $scope.refresh - a function for updating the content of the page - you can replace it with your own.
var stop = $interval($scope.refresh, 1000);
$scope.$on('$destroy', function() {
$interval.cancel(stop);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question