I'm currently in the process of evaluating different JS frameworks for a project and I find myself torn between Angular and Ember. As I continue to explore Angular, I have a specific question regarding data binding to an external json file stored on S3.
My intention is to build a live scoreboard using data that will be updated regularly on S3, typically every 15 seconds or so.
Presently, I have a basic scoreboard page displaying data from a local json file. However, I am wondering if there is a way for the data in index.html to automatically update when changes occur in the json file, or if I will need to implement some sort of callback mechanism?
Any insights or guidance on this matter would be greatly appreciated. Thank you!
// app.js
var App = angular.module('App', []);
App.controller('ScoreboardCtrl', function($scope, $http) {
$http.get('scoreboard.json')
.then(function(res){
// Storing the json data object as 'scores'
$scope.scores = res.data;
});
});
The objective is to generate a dynamic scoreboard by cycling through the scores:
<!doctype html>
<html ng-app="App" >
<head>
<meta charset="utf-8">
<title>LIVE</title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="ScoreboardCtrl">
<ul>
<li ng-repeat="score in scores">
{{score.home_team_score}} - {{score.away_team_score}}
</li>
</ul>
</body>
</html>