Displaying a single result in Angular from JSON without using the ng-repeat filter

Currently, I am working on developing an app to display news updates from a JSON API. The issue I am facing is that loading all the data from the JSON and filtering it using ng-repeat is causing slow performance, as there is a large amount of data.

I would like to modify the code so that only one row is selected in the controller, making it easier to load into the detail page.

Additionally, I want to order the news in descending order. While I have used | orderby for this purpose, loading all the data at once is impacting the speed of the app. My goal is to implement a swipe-to-refresh feature that initially displays only 8 posts and loads more data when swiped, similar to how Twitter works.

Controller.php

.controller('MediaCtrl', function($scope, $http) {

  $http.get('http://api.pemiluapi.org/rekam-jejak-media/api/rekam_jejak?apiKey=c6a0237499f3e4197546b5551a3a864f')
       .then(function(res){
          $scope.medias = res.data;  
          //alert(res.data);              
        });


})

.controller('MediaDetailCtrl', function($scope, $stateParams, $http) {

  $http.get('http://api.pemiluapi.org/rekam-jejak-media/api/rekam_jejak?apiKey=c6a0237499f3e4197546b5551a3a864f')
       .then(function(res){
          $scope.medias = res.data;  
          $scope.mediaid = $stateParams.mediaId;
          //alert(res.data);              
        });


})

Detail.html

   <ion-content style="padding:30px;" class="item-remove-animate " ng-repeat="media in medias.data.results.rekam_jejak | filter: {id: mediaid}" type="item-text-wrap" href="#/tab/daerah/{{province.id}}">

Media.html (all news)

 <ion-item class="item-remove-animate " ng-repeat="media in medias.data.results.rekam_jejak | orderBy:'id':true" type="item-text-wrap" href="#/tab/media-detail/{{media.id}}">

Thank you for your assistance :) Let's collaborate!

Answer №1

Have you worked with the Ionic framework before? The Ion-content directive is specifically designed for use within the Ionic framework. When dealing with long lists of items, it's recommended to utilize collection repeat instead of ng-repeat for improved performance.

Consider implementing the following code snippet to display the list of items:

<ion-content>
    <ion-item collection-repeat="media in medias.data.results.rekam_jejak">
        <a ng-href="#/{{media.url}}">{{media.id}}</a>
    <ion-item>
</ion-content>

If a user clicks on the link, your configuration should include a route that leads to a unique view template and associated controller for that specific item. By adopting this method, you can avoid any potential performance issues on the detail page as there won't be a need for ng-repeat.

If my interpretation of your issue is incorrect, please inform me so I can provide further assistance.

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

Why does it appear that Angular is undefined in this straightforward Angular demonstration?

I'm completely new to AngularJS and I've encountered an issue. Yesterday, I ran a very simple AngularJS application that I downloaded from a tutorial and it worked perfectly. The application consists of 2 files: 1) index.htm: <!DOCTYPE htm ...

The socket context provider seems to be malfunctioning within the component

One day, I decided to create a new context file called socket.tsx: import React, { createContext } from "react"; import { io, Socket } from "socket.io-client"; const socket = io("http://localhost:3000", { reconnectionDela ...

What could be causing the issue with npm install packages not functioning properly?

Currently, I am in the process of setting up and deploying a particular git repository locally: https://github.com/maxie112/gatsby-ecommerce-theme I am strictly adhering to the instructions provided for Mac OS. Here are the encountered error logs; maxden ...

Utilizing the scope in conjunction with ng-model within an md-select element, along with ng-repeat, for the purpose of storing

Need help fixing two bugs in my phonegap app development. I'm creating a take-out app with Menu, Options, and Order sections. In the Options page, there are checkboxes and a dropdown using md-select. Currently, when a user selects an option from the d ...

What could be causing ng-repeat to malfunction?

My ng-repeat is not working with the table - only the header part is being displayed in the output. I have checked my binding and it seems to be correct, but I know I am missing something. Can someone please help me figure out what I am doing wrong? JAVA ...

What is the best way to translate this code into JQuery ajax?

I have some code here that is currently using Javascript AJAX. I'm interested in converting it into jQuery AJAX, can someone help me with this? var mine = new XMLHttpRequest(); mine.onreadystatechange = function() { if (mine.readyState == 4 &am ...

Is it possible that activating the alert() function within a Node.js script could cause the server to freeze completely?

Given that Node.js operates on a single thread, is there a risk of freezing the entire server by calling functions like alert(), which typically wait for user input? Does Node.js have mechanisms in place to prevent such issues? ...

Unfulfilled commitment on bcrypt

I am currently facing an issue while trying to validate a user's password using bcryptjs. I have implemented a function that returns a Promise, but I am encountering an error when reaching the bycrypt.hash step - all I see is Promise { <pending> ...

Using JQuery to handle multiple JSON requests with deferred or promise methods resulted in errors

Our application allows users to load data via Ajax requests. For example, we have a selection of items known as 'tracks'. When a user clicks on a track, an Ajax request is triggered to retrieve and display the corresponding data. Each track is en ...

Create a random word from a single string within the data in Nuxt.js

I am in need of assistance. In my Vue Nuxtjs project, I am fetching random words generated from my backend Laravel application through an API response. I need to generate multiple random words from a single string value in the data obtained from my Axios r ...

After updating to the latest npm version, the NodeJS server continues to display the error message "Upgrade Required" when loading pages

After developing a Node project using NodeJS version 5.4.x and NPM version 3.3.12 on Windows, I encountered an issue where the project throws an "Upgrade Required" message (HTTP Error code - 426) upon loading the page after some time of inactivity. To add ...

Is it possible to incorporate a map into my HTTP API to enhance its flexibility and functionality?

My http api utilizes JSON to transmit parameters, which appear as follows: { param1: xxx param2: xxx param3: xxx } However, my system operates using a plugin system where each plugin requires its own set of parameters within the JSON body. All plug ...

Deciphering intricate JSON structures using PHP

In my current situation, I am receiving a server response with mixed data and now I need to handle it using PHP. Array ( [14424174] => Array ( [0] => Array ( [id] => 45 ...

The comparison between StrictNullChecks and Union Types in terms of syntax usage

Understanding StrictNullChecks in TypeScript Traditionally, null and undefined have been valid first class type citizens in JavaScript. TypeScript formerly did not enforce this, meaning you couldn't specify a variable to potentially be null or unde ...

Text Separation Within a Singular JSON Object

Currently, I am offering my assistance as a volunteer to develop a fast AngularJS App for a non-profit organization. Although I have successfully set up Angular, the main issue I am encountering has to do with parsing JSON data. The JSON object that I am ...

Enhancing SVG graphics dynamically with JavaScript and ensuring compatibility across different web browsers

I am currently working on incorporating an element into an existing SVG file. Interestingly, the process runs smoothly on Chrome and Firefox but encounters issues on Edge. I aim for it to function seamlessly on the latest versions of all three browsers, wi ...

Font in Three JS not loading properly

I'm attempting to use TextGeometry in my project to incorporate text. var shape = new THREE.TextGeometry( 'Hello, World!', { size: 60, height: 20, curveSegments: 3, font: 'helvetiker', weight: ' ...

JavaScript for validating forms in PHP

Hey everyone, I'm struggling to understand why the alert box isn't showing up when I run this code. I'm new to programming and find HTML easy, but I'm currently in a PHP class where we have been tasked with creating and validating a for ...

Migrating from Morphia to Java Mongo Driver 3.0 and need to know how to deserialize a JSON document retrieved from mongoDB into a Plain Old Java Object (POJO)?

BACKGROUND Initially, Morphia was used to communicate with a mongo database which worked well except for a mapping exception that kept appearing in the logs. Here is my Unresolved Question regarding this issue. <=== Despite this issue, Morphia successf ...

Display only distinct dates in the ng-repeat list

I'm trying to display an unordered list created using ng-repeat. Each list item includes a month header and a blog post. I'm struggling to find a clean solution to only show one instance of each month name without resorting to complex jQuery hac ...