I use an http get request in angular for extract data in a object with the users connected at the moment in my app. But that info need to be refreshed every time for bind to the scope. So I made this for refresh every 3 seconds the data of the array in get request ->
index.jade
a(ng-repeat="item in room.connected")
img(src="/images/{{item.avatar}}")
controller.js
ngApp.controller('controller', function(){
var vm = this; vm.connected;
$interval(function(){
//The Get request returns an array like->[{"username":"cesarodriguez4","avatar":"icon-user-man-1.png"}]
$http.get('http://localhost:3000/get-classroom-viewers/user')
.then(function(response){
vm.connected = response.data;
},function(error){
console.log(error);
});
}, 3000);
//Every 3 seconds executes the GET request.
});
That works, but i think its not the correct, because the terminal shows every time the get request and I think that's a bad practice Does an method for refresh the info only when the server changes the data? I try Using $scope.$watch but does not work.