Reputation: 219
I would like to create a website that fetches data from several APIs and display them. Because I wanted to try and lean AngularJS I deceided to use it for this project.
My problem is that I do not know how to fetch data every x seconds in an easy way, so the feed keeps live and shows new events as quick as possible.
Upvotes: 0
Views: 1346
Reputation: 16498
You can use $interval please see demo below:
More info you can find here https://docs.angularjs.org/api/ng/service/$interval
var app = angular.module('app', []);
app.controller('firstCtrl', function($scope, $interval) {
$scope.data = "";
$interval(function() {
//update $scope.dataevery 1000ms
$scope.data = new Date();
}, 1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="app">
<div ng-controller="firstCtrl">
{{data | date : 'medium'}}
</div>
</body>
Upvotes: 3