Flipping the object order in Angular with ng-repeat

Ordering Filter

app.filter('orderObjectBy', function() {
  return function(items, field, reverse) {
    var filtered = [];
    angular.forEach(items, function(item) {
      filtered.push(item);
    });
    filtered.sort(function (a, b) {
      return (a[field] > b[field] ? 1 : -1);
    });
    if(reverse) filtered.reverse();
    return filtered;
  };
});

Data of JSON:

{
  "results": {
    "100": {
      "numbers": {
        "1": {
          "key": "value"
        },
        "2": {
          "key": "value"
        },
        "3": {
          "key": "value"
        }
      }
    },
    "200": {
      "numbers": {
        "1": {
          "key": "value"
        },
        "2": {
          "key": "value"
        },
        "3": {
          "key": "value"
        }
      }
    }
  }
}

Show on screen:

<div ng-repeat="(k,v) in results">
  <span ng-repeat="(k1,v1) in v | orderObjectBy:k1:true">{{k1}}</span>
</div>

The issue with orderObjectBy:k1:true is that it returns an array of keys rather than the values. To rectify this and reverse the order, we need to make adjustments. How can we accomplish this?

Answer №1

Why not give this a shot?

ng-repeat='element in elements | orderBy: element.name:desc'

Another option could be

ng-repeat='element in elements.reverse()'

Answer №2

When working on my bicycles content management system (where bikes are objects), I needed to reverse the order of the bikes list.

Here is how I achieved the reversal:

<tr ng-repeat="bike in bikes | orderBy: '-' ">

I hope this solution can be helpful to others! :D

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

What triggers the onmouseout event to occur?

Is the event triggered continuously whenever the mouse is not hovering over the element? Or is it a one-time action when the mouse exits the element? This distinction is crucial for me to determine when the mouse pointer leaves the element, while only wa ...

Adjust the size of the div to match its parent's size when resizing

Can a div be resized to match its parent's size on window resize? Here is the current HTML code: <div class="sliderContainer"> <div id="cyler"> <div class="cy1" style="background-image:url(images/Keggy_Banner_Ie.jpg); back ...

Implementing a loading spinner in React Native until the component is fully mounted

I am dealing with a List component that takes some time to load. I am trying to display a spinner until the component is loaded and mounted, but all my attempts have been unsuccessful. Here is the approach I am currently attempting: class List extends R ...

Error: Unable to iterate through the {(intermediate value)}. It's not a function

Snippet of the original code: const genreOptions = [{{ genreOptions | json_encode | raw }}].map((type , label) => ({value: type, label: label})); Piece of debugging code: const genreOptions = { "Horror": "Kork ...

Guide for controlling inline SVG with vuex

Currently, I am working on a customizing tool for cursors using Vuejs and Vuex. My main challenge lies in the process of binding the color selected by the user to the fill property of an SVG cursor. Allow me to explain step by step how everything is suppos ...

I am able to fill in the ServiceType field, but I am struggling to find the correct options for the ServiceName dropdown menu

Is there a way to dynamically update the ServiceName dropdown options based on the selected value in the ServiceType dropdown? $scope.ServiceTypeAndName = [ { "id":0, "type":"", "list":"" }, { "id":1, "ty ...

transforming a cylindrical shape into a curved pipe

Utilizing the capabilities of three.js, I have successfully engineered a captivating scene featuring a textured and meshed cylinder along with a grid boasting lines and vertices. By manipulating the mouse to the left or right, the cylinder elegantly spins ...

Stop the occurrence of rapid double clicking on a link button within a Repeater control

When I try to fast double click, the JavaScript function Show() gets called (displaying "please wait"), but Button_Click in vb.net does not get called. Any suggestions on how I can solve this issue? Here is my code snippet: ASPX <ItemTempla ...

In Typescript, you can easily group a string into sections that consist of digits like 345-67, along with text containing a

I have a string that looks like this: "[111-11] text here with digits 111, [222-22-22]; 333-33 text here" and I am trying to parse it so that I can extract the code [111-11], [222-22-22], [333-33] along with their respective text descriptions. The challeng ...

Vue 2.0 custom filter not producing any output

I am attempting to create a customized filter that identifies and returns the items that correspond to a given input. It functions effectively with basic arrays like ['Apple', 'Banana', 'Cupple'], but encounters difficulty whe ...

Updating an image using AJAX and Flask

I have a situation in HTML where I need to constantly update an image file with the latest images that come in. Below is the Flask code snippet: @app.route('/uploads/update_file', methods=['GET', 'POST']) def update_file(): ...

Having trouble with a tslint error in Typescript when creating a reducer

I encountered an error while working with a simple reducer in ngRx, specifically with the on() method. https://i.sstatic.net/9fsvj.png In addition, I came across some errors in the reducer_creator.d.ts file: https://i.sstatic.net/sWvMu.png https://i.ss ...

Puppeteer Alert: Page has crashed while attempting to retrieve a fully loaded page with body contents

Whenever I use request or axios to scrape, the body is empty. <!DOCTYPE html><html> <head> <!--Missing Head content --> </head> <body> <ui-root></ui-root> <script type="text/javascript" src=& ...

Setting the default <a-sky> in Aframe: A step-by-step guide

There was a fascinating projection I witnessed where two images were displayed in the sky. [https://codepen.io/captDaylight/full/PNaVmR/][code] Upon opening it, you are greeted with two spheres and a default white background. As you move your cursor over ...

What is the best way to generate a search link after a user has chosen their search criteria on a webpage?

In my search.html file, I have set up a form where users can input their search criteria and click the search button to find information within a database of 1000 records. The HTML part is complete, but I am unsure how to create the action link for the for ...

what is the procedure to obtain the return message from store.sync();

function processButtonClick(){ var gridData = Ext.getCmp('mygridpanel'); var selectedRow = gridData.getSelectionModel().getSelection()[0]; var vehicleIDInput = Ext.getCmp('txtVehicleID').getValue(); ...

Error in fullCalendar where events are appearing on incorrect days in the month view of the current month

https://i.sstatic.net/v8Faj.png My fullcalendar plug-in is causing some trouble. I'm trying to show events in the monthview of the calendar, but when I'm in the current month, events on the same day of the week are not displaying correctly. They ...

Steps to visualize an array of objects on a graph using Chart.js

Hey there! I'm facing an issue while trying to display my array of objects in a Chart.js graph. Here's the code snippet: let timers = {neutral: 0, happy: 0, sad: 0, angry: 0, surprised: 0, disgust: 0}; var detection = new Chart(c, { type: &ap ...

How to handle a checkbox click event within an UpdatePanel using jQuery

I've been working on an update panel that includes a runat server div. Initially, the div is not visible when the page loads. My goal is to display it after the user enters a search key, reloads the update panel containing the div, fills the div contr ...

JavaScript PIP video feature

Currently, I am utilizing the requestPictureInPicture function to display the HTML video element in a popup window. However, I have encountered an issue where the size is restricted to approximately 920 x 540 when in Picture-in-Picture mode. I am wonderin ...