I have some issues with automatically updating a code in Angular.js inside my site. The integration is Node.js with HTML, integrating with Angular.js. However I have to always give F5 on the page so it updates the variable "Temperature". I would like to integrate into the system the automatic update, upon receiving the POST command on node.js
UPDATE index.html
<html lang="pt-br" ng-app="angular">
<div ng-controller="myController">{{data}}</div>
<script>
var app = angular.module('angular',[]);
app.controller('myController', function($scope, $http, $interval) {
$scope.data = [];
getData();
function getData () {
var request = $http.get('/Temperatura');
request.then(function(data) {
$scope.data = data + " ºC";
},function(data){
console.log('Error: ' + data);
});
request.finally(function () {
$timeout(5000, getData);
});
// O finally é executado sempre que a requisição terminar de executar, independente se o retorno for sucesso ou erro
});
</script>
Node.js
app.post('/EnviaTemperatura', function(req, res){
temperatura = req.body.temp;
res.send('Temperatura: ' + temperatura);
});
app.get('/Temperatura', function(req, res){
res.send(temperatura);
});
I searched to integrate INTERVAL, an Angular module in this code, but I could not.
How can I make my project turn "Real Time"?