Updating/Timer feature for a single feed out of two -- Combining data with $q.all()

I'm revisiting a question I previously asked here.

The approach I took involved using the $q.all() method to resolve multiple http calls and then filtering and merging the data. Everything was working fine, but now I want to refresh one of the feeds every 5 minutes. Usually, I would add a timer at the end of my code like this:

var timer = $scope.intervalFunction = function() {
    $timeout(function() {
       /* function to call $http.get again */
        $scope.intervalFunction(); 
    }, 300000)
}; 
timer(); 
$timeout.cancel(timer); 

My challenge is figuring out how to update just one source without duplicating list items when both sources are merged together. This has been an issue for me in previous attempts.

Any suggestions or insights would be greatly appreciated! Thank you!

JSFiddle link: here

Answer №1

"I'm looking to refresh one of my two feeds every 5 minutes." It may not be possible to achieve this using a single $q.all request. One workaround could be to make an additional request outside of the $q.all wrapper and then initiate a $timeout after receiving results from the first $q.all request.

I should mention that I haven't tested this solution myself, but it might work:

$q.all(promises)
  .then(function(response) { 
    metadata = response.metadataPromise.data;
    metrics = response.metricsPromise.data; 
    joinMetadataAndMetrics();
    requestEveryFiveMinutes(); 
  })
  .catch(function(error) { 
    console.log(error);
  });

function requestEveryFiveMinutes() {
  $interval(function() {
    // Perform the necessary http request here
    yourRequest()
      .then(function() {
        // Handle the response accordingly
      })
      .catch(function(err) {
        console.log(err);
      })
  }, 300000);
}

Don't forget to inject $interval in your controller.

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

Bidirectional linking using URL query parameters and form inputs (select boxes and sliders)

Presently, I am able to retrieve the GET parameters using $location.$$search. Nevertheless, I am still unsure about how to implement 2-way binding for both the URL and FORM in the following scenario. In the demo image below, when a user updates the FORM ...

Receiving an 'undefined' result in an asynchronous response even with 'await' and 'then' statements implemented

I'm struggling with sending a GET request, parsing the response, and passing it to another function. It seems like I'm having difficulty dealing with the asynchronous nature of the response. I prefer to stick to using Node.js' built-in modu ...

What is the best way to generate an @ symbol using JavaScript?

When coding in Javascript, a challenge I am facing is creating a variable that includes the @ symbol in a string without it being misinterpreted as something else, especially when dealing with URLs. Does anyone have any suggestions on how to handle this ...

Progress bar for AJAX file loading for Flash player

Looking to create a progress bar using AJAX for a flash file. Check out this demo here: I tried to analyze their page, but the JavaScript is encrypted and I'm not very skilled in JS. Any suggestions? Thank you! ...

How can I access an object in ng-model in AngularJS?

When a user selects a client from the list, I want to display the client's ID and country. Currently, I can display the entire selected object but not the specific client details. <label class="control-label red">Client</label> ...

retrieving information from a secondary window

Currently, I am working on a project and have come across an issue. Please take a look at the following code snippet: <iframe name="stus" id="stus" style="display:none;"></iframe> <form name="water" id="water" method="post" autocomplete="of ...

When an element in vue.js is selected using focus, it does not trigger re

One of my tasks involves tracking the last selected input in order to append a specific string or variable to it later on. created: function () { document.addEventListener('focusin', this.focusChanged); } focusChanged(event) { if (event ...

Remove the icon disc background from a select element using jQuery Mobile

As I delve into building my first jQuery Mobile app using PhoneGap/Cordova, I have encountered some challenges along the way in getting the styling just right, but overall, things are going well. However, when it comes to working with forms, I hit a roadb ...

What is the proper way to pass data inside a function within a $scope in AngularJS?

$scope.information = {name:"harold", age:"25", address:"california USA",}; function copyData() { $scope.information = angular.copy($scope.information); }; I'm trying to find a way to simplify copying data from one object to another within a fu ...

Replacing the useEffect hook with @tanstack/react-query

Lately, I made the decision to switch from my useEffect data fetches to react-query. While my useEffect implementation was working flawlessly, I encountered various issues when trying to directly convert my code for react-query. All the examples I found ...

Configuring API paths based on environment variables with Express and Angular deployed on Heroku

I have a specific task I need help with, and I'll provide more details below. In my main Angular JavaScript file, I need to define a string that determines the server path for my app depending on whether it's in a production or staging environme ...

Include a for loop in the line graph on Google Charts

I need help figuring out how to use a for loop to iterate over data in order to populate my Google Chart. The code snippet below outlines what I've already tried. var line_div = '2016-08-04,4|2016-08-05,7|2016-08-06,9|2016-08-07,2'; var lin ...

Having trouble with your HTML iFrame not functioning properly?

My code is not working as expected and I'm puzzled by it. It was working fine yesterday but now it's giving me trouble. <iframe allowfullscreen="" allowtransparency="true" frameborder="0" height="2000" scrolling="no" src="http://www.google.co ...

Testing the functionality of an Express Rest API with Mocha unit tests

I have just started diving into the world of unit testing. While I've been successful in running simple tests such as "adding two numbers and checking if the result is greater than 0", my goal now is to develop a REST API using Test-Driven Development ...

Extension for capturing videos on Chrome or Firefox

I am interested in developing a Chrome or Firefox extension that can capture video from a window or tab. My goal is to record full screen videos, such as those on YouTube, for offline viewing similar to a DVR for online content. Creating an extension see ...

Activating Unsplash API to initiate download

I am currently following the triggering guidelines found in the Unsplash documentation. The endpoint I am focusing on is: GET /photos/:id/download This is an example response for the photo: { "id": "LBI7cgq3pbM", "width": ...

Tips for incorporating MUI into your Redwood JS project

Trying to integrate MUI into Redwood JS has been a challenge for me. I attempted to run the following command in the project directory: yarn add @mui/material Unfortunately, an error message appeared in the console stating: An error Running this command w ...

Display elements on hover of thumbnails using CSS

I'm struggling with the logic of displaying images when hovering over corresponding thumbnails using only CSS. If necessary, I can do it in JavaScript. Here's my latest attempt. <div id='img-container' class='grd12'> ...

What could be the reason for the sender message to only display once the recipient sends a message? (socketio) (nodejs) (reactjs)

Currently, I am working on developing a real-time chat application using Node.js, React, and Socket.io. The chat functionality is operational in theory, but there seems to be an issue where the sender's message only appears on the recipient's scr ...

Increase the value of $index within the ng-repeat loop

Is there a way to increment the value of $index in ng-repeat by a specific amount? For example, if I want to display two values at a time, how can I ensure that the next iteration starts with the third value instead of the second value? <div ng-contr ...