Incorporate JSON data into an existing array within Angular that already contains JSON data

I have a problem with adding new jsonp data to an existing array while loading more content near the bottom of the page. Instead of appending the new data, it replaces what's already there.

function AppCtrl($scope, Portfolio, $log, $timeout, $ionicSlideBoxDelegate) {
    $scope.posts = [];
    Portfolio.getPosts($scope);
    $scope.refresh = function() {

        console.log('Refreshing!');
        $timeout( function() {

        Portfolio.getPosts($scope);

        console.log('Refreshed!');

        //stop the ion-refresher from spinning
        $scope.$broadcast('scroll.infiniteScrollComplete');

        }, 1000);

    };

//fetching jsonp data
function Portfolio($http, $log) {
    this.getPosts = function($scope) {
        $http.jsonp("http://test.uxco.co/json-test.php?callback=JSON_CALLBACK")
            .success(function(result) {
                $scope.posts = result;  
                $scope.$broadcast("scroll.infiniteScrollComplete");
            });
    };
}

Any suggestions on how to fix this issue?

Thank you!

Update:

$scope.posts.push(result);

The above solution seems to work but now the content isn't displaying correctly.

<div data-ng-repeat="p in posts">
      <div class="img-container">
          <img ng-src="{{ p.thumbnail }}">
      </div>
      <div class="title-container">
          <h2>{{ p.id }}</h2>                   
      </div>
</div>

Answer №1

function InvestmentPortfolio($http, $logger) {


    this.fetchInvestments = function($scope) {
        $http.jsonp("http://example.com/data-fetch.php?callback=JSON_CALLBACK")
            .success(function(data) {
                $scope.investments.push(data);  
                $scope.$emit("scroll.triggerFetchComplete");
            });
    };
}

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

The string obtained from input.getAttribute('value') is lacking one character

While developing e2e-tests for an angular application, I encountered a puzzling issue. When trying to retrieve the value from an using the .getAttribute('value') method, I noticed that a single character was missing. Checking the HTML properties ...

Angular 6 canvas resizing causing inaccurate data to be retrieved by click listener

The canvas on my webpage contains clickable elements that were added using a for loop. I implemented a resizing event that redraws the canvas after the user window has been resized. Everything works perfectly fine when the window is loaded for the first ti ...

JavaScript Function to Convert JSON Data into an Excel File Download

I am looking for help with converting JSON data received from an AJAX POST Request into an Excel file (not CSV) for download on a button click. The JSON Data may contain blank values and missing fields for each JSON row. I have attempted to achieve this o ...

Categorize an array by shared values

Here is an example of my array structure: myArray = [ {SKU: "Hoo12", Name: "ACyrlic watch",OrderNo:"26423764233456"}, {SKU: "S0002", Name: "Princes Geometry",OrderNo:"124963805662313"}, {SKU ...

Is there a way to execute the UNet segmentation model in Javascript using TensorFlow JS?

I recently trained a UNet model in Python and saved the model as a Model.h5 file. Following the instructions in the tensorflow JS documentation on How to import a keras model, I used the tensorflowjs_converter tool to convert the model into a Model.json fi ...

Rendering components asynchronously in ReactJS

After completing my ajax request, I need to render my component. Here is a snippet of the code: var CategoriesSetup = React.createClass({ render: function(){ var rows = []; $.get('http://foobar.io/api/v1/listings/categories/&apo ...

Transforming Arrays of Objects into a Single Object (Using ES6 Syntax)

My attempt to create aesthetically pleasing Objects of arrays resulted in something unexpected. { "label": [ "Instagram" ], "value": [ "@username" ] } How can I transform it into the d ...

`The Issue with Ineffective Slider Removal`

Below is the complete code: import React, { Component } from "react"; import "./App.css"; import Slider from "@material-ui/core/Slider"; import Typography from "@material-ui/core/Typography"; class App extends Compo ...

Having trouble retrieving data with the componentDidMount API call in React?

I'm currently in the process of building a Gallery feature. Initially, I hardcoded the image links, but now I want to fetch them using an API call. The implementation didn't go as planned, and it's still pulling the hardcoded images from the ...

"click on the delete button and then hit the addButton

I have created a website where users can save and delete work hours. I am facing an issue where I can save the hours at the beginning, but once I delete them, I cannot save anything anymore. Additionally, when I reload the page, the deleted data reappears. ...

Do not fulfill the promise until all the images have finished loading

Below is the intended process: Iterate through a collection of img tags Retrieve each tag's src URL Convert it to a base64 encoded string using an HTML 5 canvas Once all images have been converted, resolve the promise and call the callback function ...

Webpack failing to load jQuery correctly

In the process of transitioning my application.js application into smaller page bundles using SplitChunks, I have encountered a situation in my users/show.html.erb page where I am utilizing the following tag to import the specific chunk. <%= javascript ...

JavaScript: Utilizing numbers to extend a sequence

My code is saved in a Google Sheets document and here is how it looks: ss = SpreadsheetApp.getActiveSpreadsheet(); function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = [ {name: "10 Rows", functionName: "TenRows"}, ...

Extract information from a JSON string stored in a variable and transform it into objects within the $scope.variable

I currently have a string variable that contains JSON data displayed below. var jsonstring = [{"latitude":"51.5263","longitude":"-0.120285","altitude":"","device":"123","rating":"5","region":"Europe","customer":"","time":"1-2 Weeks","error":"Error 1","app ...

Generating procedural textures for particles within the context of three.js

I am working towards creating a particle system that involves procedurally generated textures for each particle's vertices. However, I am facing challenges in developing a prototype that can function seamlessly under both the Canvas and WebGL renderer ...

JsDoc presents the complete code instead of the commented block

I have a VUE.JS application that needs to be documented. For .VUE components, we are using Vuese. However, when it comes to regular JS files like modules, we decided to use JsDoc. I have installed JsDoc and everything seems fine, but when I generate the HT ...

Resizing a webpage to fit within an IFRAME

Having just started learning HTML, CSS, and JavaScript, I am attempting to incorporate a page as a submenu item on my website. Below is the code that I have so far: <!DOCTYPE html> <html> <meta name="viewport" content="width=1024"> ...

Alter the truth value of an item contained within an array

Embarking on my JavaScript journey, so please bear with me as I'm just getting started :) I am working on a small app where the images on the left side are stored in an array. When a user clicks on one of them, I want to change its height and also tog ...

Creating a Pre-authentication service for AWS Cognito using VueJS

Implementation of Pre-Authentication feature is needed in my VueJS application for the following tasks: Validation of ID/Refresh Token to check if it has expired. If the IdToken has expired, the ability to re-generate it using the Refresh Token or altern ...

Adding fields to all objects in an array within MongoDB

I'm trying to update all objects in an array by adding a new field only if it doesn't already exist. I attempted to use the updateMany method but it doesn't seem to be working. Can someone please assist me? const updateResult = await Form.up ...