0

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.

1 Answer 1

3

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.