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

The division element nested within a select tag

HTML: <div class="row"> <div class="form-group"> <div class="col-xs-10"> <label for="class_code_reservation">Class Code</label> <select type="text" class="form-control" id="class_code_reservation" na ...

Error: The property 'parentNode' cannot be read because it is null

I wanted to test if my laptop can handle WebGL by loading examples from my instructor's webpage. The examples on the webpage worked fine, just showing a square within a square. I then decided to copy the exact codes into a notepad text editor, saved t ...

Demonstrate the utilization of JQuery to unveil a secondary menu

I need assistance in implementing a sub-menu that automatically appears within 2 seconds after the page loads, instead of requiring user interaction. I am currently utilizing JQuery, which serves as the core framework for my website. It is crucial for this ...

Easy steps to dynamically add buttons to a div

I need help with a JavaScript problem. I have an array of text that generates buttons and I want to add these generated buttons to a specific div element instead of the body. <script> //let list = ["A","B","C"]; let list = JSON.p ...

What is the best way to show and hide the information in a FAQ section when each one is clicked?

const faqItems = document.getElementsByClassName("faq-question"); const faqContents = document.getElementsByClassName("faq-content"); for (item of faqItems) { console.log(item); item.addEventListene ...

The attempt to remove a cookie through a Next.js server-side operation was unsuccessful

Having trouble removing a cookie using the next/headers module in my Next.js application. The code snippet below is what I've tried: import {cookies} from "next/headers"; export default async function Signout() { async function deleteTok ...

Using the Codable protocol in Swift 4 to map JSON data to keys represented

Utilizing Swift 4's codable feature with JSON poses a challenge due to undefined keys represented as ids in an array structure like: { "status": "ok", "messages": { "generalMessages": [], "recordMessages": [] }, "foundRows": 2515989, "data ...

Getting the output from AJAX when the onreadystatechange event occurs

Struggling with retrieving a value from a function and storing it in a variable? Getting an "undefined" result due to JavaScript's asynchronous nature? Unsure how to fix this using "callbacks" or "promises"? Check out the code snippet below. The goal ...

Struggling to set the value for a variable within an Angular factory?

When dealing with a variable as an array, I have no trouble pushing objects inside and retrieving the values within the controller. However, when trying to directly assign an object to that variable, I run into issues. If anyone can assist me in achieving ...

Exploring the World of JSON File Parsing in Unity line by line

{ "Recipes": [ { "Tag": "Salad", "Ingredients": [ "Tomato", "Olive oil", "Thyme", "Lemon", "Black Pepper", ...

An in-depth guide on how to recursively update the value of a JsonNode using Jackson

Requirements: I'm looking to utilize various functions on the values within a JsonNode. These functions could range from lowercasing certain values, appending data to values, or completely replacing them. How can I implement this functionality using ...

The disappearing act of Redux state after being added to a nested array

When attempting to update my redux state, I am facing an issue where the state disappears. My approach involves checking for a parentId - if one exists, I insert the payload into the parent's children array. However, if no parentId is provided, I simp ...

Why does the header still show content-type as text/plain even after being set to application/json?

When using fetch() to send JSON data, my code looks like this: var data = { name: this.state.name, password: this.state.password } fetch('http://localhost:3001/register/paitent', { method: 'POST&a ...

How to send JSON data using HTTP POST in iOS?

My attempt at this code is resulting in an unauthorized error being returned AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager setRequestSerializer:[AFJSONRequestSerializer serializer]]; [manager.requestSeriali ...

Is there a way to make a React Component to update and navigate to a specific position using react-sound

Currently, I am in the process of constructing an audio player utilizing react-sound. One feature I aim to incorporate is the ability to return to a specific position within the audio track. At the moment, this is my approach: goToVeryCustomPosition() { ...

How can I initiate a TextChange event in ASP.NET C# without losing focus?

I attempted to trigger the TextChange event using Ajax, but it doesn't seem to be working as I expected. I'm hoping someone here can lend a hand. <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> ...

Large data sets may cause the Highchart Bar to not display properly

Currently, I am working on a web project that displays traffic usage in chart mode using Highchart Bar. The issue I am facing is that there are no errors thrown when running this code. <script type="text/javascript"> $(function () { $(&apos ...

retrieve the value of a specific key from an array

How can I extract key-value pairs from an array in JavaScript where the data is structured like this? jsonData = [ {"dimensions":[5.9,3.9,4.4,3.1,4.8],"icon":0,"curves": [false,false,false,false,false],"id":"p1","color":"0x000000"}, {"dimensio ...

The concept of undefined does not hold any tangible form

TypeError: undefined is not an object (evaluating 'this.props.data.map') appContent: displayData(){ let info = this.props.data.map(function(dataItem, index) { return ( <Card> <CardItem> <Body ...

Ways to effectively handle diverse Angular module dependencies

Although I am still new to Angular, I have been striving to write more modular code and rely less on cramming logic into the controller. Instead, I have been utilizing independent services. However, a recurring issue I am facing is having to re-declare the ...