Using Angular to Bind JSON Data

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>

Answer №1

How can I ensure that the data in index.html reflects changes in the json file?

The data in index.html should update automatically when you change $scope.scores.

If you want to update it from the live server, you can set a timer using setInterval (or the $timeout service) and make a $http.get call at regular intervals.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vue js throws a maximum call stack error when updating a Chart component

I have successfully created a line chart using the Chart.js 3.5 library. The chart is responsive, all animations are working fine too. I am currently facing an issue where I am attempting to update the data from a parent component and trigger a chart updat ...

The Carousel feature functions properly with 3 or more slides, but malfunctions when there are only 2 slides present

After implementing a minimal carousel, I discovered that it functions perfectly with 3 or more slides. However, as soon as I remove some slides, issues start to arise. Some of the problems I encountered include: The sliding animation is removed on ' ...

How can a loading indicator be displayed while retrieving data from the database using a prop in a tabulator?

Incorporating a tabulator component into my vue app, I have set up the Tabulator options data and columns to be passed via props like this: // parent component <template> <div> <Tabulator :table-data="materialsData" :ta ...

How can I trigger an Onclick event from an <a tag without text in a Javascript form using Selenium?

Here is my original source code: <a onclick="pd(event);" tabindex="0" issprite="true" data-ctl="Icon" style="overflow: hidden; background: transparent url("webwb/pygridicons_12892877635.png!!.png") no-repeat scroll 0px top; width: 16px; height: 16px ...

Ways to extract pertinent information from a PHP API

I've been attempting to add parameters to my query, but I keep getting inconsistent results. Despite trying different methods, I haven't been successful. Take a look at the code below. First, here is my code that functions properly without using ...

Node.js Binary Search Tree - Error: Identifier Not Found

A program run through node.js has been developed to create a binary search tree with various methods like insert, remove, and print. The program is divided into two separate files: Tree.js, which exports the functions Tree() along with its methods and test ...

One can activate an event once all templates and data have been fully loaded

Is there a way to trigger an event once all templates and data have finished loading in an AngularJS application? I've completed my app, but on the production server there seems to be a delay where the templates load first and then the data follow, le ...

Deselect the checkbox that was initially selected when an alternative checkbox option has been chosen

I am trying to implement a feature where there are 2 groups of checkbox options on the same page. Below is the code snippet: <div class="col-xs-12"> <label class="checkbox-inline"> <input type="checkbox" th:field="*{borrowerRace1}" th:val ...

Ways to transform a JSON into a different JSON format while considering specific requirements

Looking for a specific jolt-script to address this issue. The concept involves one person having multiple numbers and the JSON data needing to be more concise. The JSON was flattened to achieve this. An example of the input JSON is shown below: [ ...

Inconsistency in handling express routes results in empty req.body in certain routes

I have two different paths to follow. Before each request, a method needs to be executed: app.all('*',function(req,res,next){ console.dir(req.body); // Additional operations }); When I send a POST request to my first path: $http.post ...

Enhancing many-to-many relationships with additional fields in Objection.js

I have a question that I haven't been able to find a clear answer to in the objection.js documentation. In my scenario, I have two Models: export class Language extends BaseId { name: string; static tableName = 'Languages'; st ...

Transferring information from an iOS application to a Node.js server hosting a website

After creating my own Node.js version of a Sinatra webserver using Express, I successfully implemented code on the iPhone to retrieve data from the server by sending an HTTP request for '/sushi.json'. The server handles this request using app.get ...

What is the method to modify an action in an Ajax function?

I am trying to modify the action in the AjaxUpload function. The issue is that the value of setnamefile in the action does not change because the page does not reload. My idea was to change the action on submit, but I have not been able to do so successfu ...

A guide on implementing the grid feature in Angular.js

Looking to add the following features in my Angular grid: Paging Filtering Column-wise sorting Can anyone recommend an Angular JS grid that supports these functionalities? ...

How to Eliminate the Border on the Final Item within a React List

Hi everyone, I need help with removing the border of the last item in an unordered list when the list reaches a certain size. I initially tried this: document.querySelector('.employee-list-item:last-child').style.border = "none"; However, I enc ...

Navigating Parent Menus While Submenus are Expanded in React Using Material-UI

My React application includes a dynamic menu component created with Material-UI (@mui) that supports nested menus and submenus. I'm aiming to achieve a specific behavior where users can access other menus (such as parent menus) while keeping a submenu ...

Exploring the method of implementing a "template" with Vue 3 HeadlessUI TransitionRoot

I'm currently working on setting up a slot machine-style animation using Vue 3, TailwindCSS, and HeadlessUI. At the moment, I have a simple green square that slides in from the top and out from the bottom based on cycles within a for-loop triggered by ...

Vue.js compatibility issue with SelectBoxIt jq plugin causing malfunction

On a page with numerous dynamically generated select boxes, I am looking to incorporate the jQuery selectBoxIt plugin from . Using Vue js, where is the best placement for the following code snippet to connect the plugin with the select elements? $('. ...

The communication between a Firefox XUL extension and a webpage

Currently developing a Firefox XUL extension and in need of incorporating interaction between the web page and the extension. For instance, whenever a link is clicked on the page, I would like to trigger a function within the XUL extension. Is there any k ...

Enhance Your Browsing Experience with this Chrome Extension for Page Interactions

Recently, I came across Chrome extensions and have been intrigued by their functionality. One question that has been on my mind is: how can I programmatically trigger a button click when the extension runs? For instance, there is a button with the id &apos ...