Using Nested ng-repeat for Values and Keys in Angular

Struggling with implementing nested ng-repeats in my code. I have a JSON object with multiple layers and attempting to iterate through them to display the data. Here is the structure of the JSON:

{
"status": "success",
"data": {
    "Mat": {
        "total": 0,
        "pending_devices": 0,
        "individual_counts": {
            "Mat1": {
                "total": 0,
                "pending_devices": 0,
                "locations": []
            },
            "Mat2": {
                "total": 0,
                "pending_devices": 0,
                "locations": [
                    {
                        "location1": 5
                    },
                    {
                        "location2": 2
                    }
                ]
            }
        }
    },
    "Cable": {
        "total": 0,
        "pending_devices": 0,
        "individual_counts": {
            "Flat Cable": {
                "total": 0,
                "pending_devices": 0,
                "locations": []
            },
            "L Cable": {
                "total": 0,
                "pending_devices": 0,
                "locations": [
                    {
                        "location1": 5
                    },
                    {
                        "location2": 2
                    }
                ]
            }
        }
    }
}

}

This is the looping code I am trying to use:

<md-grid-tile ng-repeat="(key, value) in vm.counts" class="{{vm.colors[$index]}}" md-rowspan="2">
  <md-grid-tile-body>
    <h2>Total:{{value.total}}</h2>
    <h2>Pending:{{value.pending_devices}}</h2>
    <p ng-repeat="(productType, productCounts) in value.individual_counts">
      <h3>{{productType}}:</h3>
      <h4>Total:{{productCounts.total}}</h4>
      <h4>Pending:{{productCounts.pending_devices}}</h4>
      <h4>Locations:</h4>
      <div ng-repeat="(location, locationCount) in productCounts.locations">
        <h5>{{location}}:{{locationCount}}</h5>
      </div>
    </p>
  </md-grid-tile-body>
  <md-grid-tile-footer>
    <h3>{{key}}</h3>
  </md-grid-tile-footer>
</md-grid-tile>

I can successfully loop through the top level but facing issues with the productType/ProductTypeCount loop and beyond. I confirmed that value.individual_counts contains the correct data. Any help would be greatly appreciated.

Answer №1

Consider using a div element instead of a p element. Paragraphs cannot wrap block-level elements.

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

Obtain the scope within a directive

Hello everyone. I am just starting to explore AngularJS and I must say, it's quite fascinating. However, I'm a little confused about the current situation. app.controller("myCtrl", ['$scope', '$http', '$filter', fu ...

I am curious to know why my jQuery when().then() function is firing before the completion of the ajax request in the when clause

I have a situation where I need to set an async callback because a function is fetching content from a remote location. Here's what I am currently doing: $.when( priv[box.view.renderWith](content, box.view.gadget_id) ).then(function(late) { conso ...

Is there a way to find the JavaScript Window ID for my current window in order to utilize it with the select_window() function in

I'm currently attempting to choose a recently opened window while utilizing Selenium, and the select_window() method necessitates its WindowID. Although I have explored using the window's title as recommended by other sources, and enabled Seleni ...

Should developers avoid using jQuery in ReactJS applications?

While working on a ReactJS project (or any other project), I personally prefer using pure JavaScript over jQuery. Lately, I've started questioning whether it's considered bad practice to use jQuery in ReactJS. Back when I was learning ReactJS, I ...

Can the variable name within a function be retrieved?

How can I retrieve the variable name (user_name1 or user_name2) from a sample function (GetUserName()) within itself? This variable name is required to create an object with the same name on the server side for data synchronization purposes. function GetU ...

PHP not displaying line breaks from JavaScript textarea

I am facing an issue while trying to generate a .txt file on my server upon form submission. Despite including newlines in the comment section, they do not show up in the resulting .txt file. Below is the code snippet I am using: Javascript function sen ...

Regular expression for matching zero's following a decimal

I'm currently working on a regex method to validate decimals that only allow 2 numbers after the decimal point. For example, it should return true for 1.00 and false for 1.000, which it currently does. However, I also want it to return false for value ...

"Simultaneously updating the UpdatePanel, triggering a JavaScript postback, and modifying the querystring in a SharePoint Search

Struggling with a tricky issue here. Let me try to clarify: I have a SharePoint results page where I'm using a Search Results Core WebPart. Now, I want to modify the parameter in the querystring upon postback so that the WebPart displays different re ...

Access Sharepoint from an external site

Looking for assistance with a SharePoint list containing columns for Name, Position, Office, and Salary. Upon logging in with specific credentials to the SharePoint website, I need to retrieve all items from the list and showcase them on my own website. ...

Encountering an issue with the file:/// error message while trying to locate the hostname in Ionic and

Utilizing Ionic and Oauth.io for authentication has been a smooth process when running ionic serve with the outh.js file included in the index. However, issues arise when switching to ionic run ios or installing the app on an Android device. Upon clicking ...

Hide the selection box when hovering over the Div

Looking for a quick solution. I want the option drop down to close when another div element is hovered over. First, open the drop down and hover over the red element on the right side. When hovering over the red element, I would like the drop down to clos ...

Angular Timer offers a single button that can handle starting, stopping, and resuming all with just

Attempting to create a progress bar with integrated Start, Stop, and Resume buttons using the "Angular Timer" directives found here (refer to the progress bar example towards the bottom). The current examples on their site consist of separate Start and Sto ...

Errors in JSON.parse: which character am I not detecting?

My development environment includes PHP 5.3.5, MySQL Server 5.5.8, and jquery version 1.6. I'm using Ajax to automatically populate a dropdown list of countries, but I keep encountering an error that persists despite trying various solutions. For exa ...

Tips for managing multiple data types within the same API on Android

Upon receiving an API response, it either returns a JSONObject when data is purchased, or a null string if not. How can I efficiently handle both data types? If attempting to specify 'Any' as the data type in my model class, I encounter issues re ...

What steps can be taken to make sure that my Ajax request has completed before executing a new function within the window.onload event

Looking for solutions using plain vanilla JavaScript only, as I do not utilize Json or jQuery currently (I have come across several solutions on SE, but they all involve jQuery or Json). There are two functions within a window.onload=function(){... event ...

"Enhancing User Experience with AngularJS by Dynamically Modifying and Refresh

I'm currently attempting to dynamically add HTML elements using JavaScript with a directive: document.getElementsByClassName("day-grid")[0].innerHTML = "<div ng-uc-day-event></div>"; or var ele = document.createElement("div"); ele.setAttr ...

What could be causing this Angular controller to throw the error message "Error: Unknown provider: nProvider <- n"?

Check out the jsFiddle code here: <div ng-app=""> <div ng-controller="FirstCtrl"> <input type="text" ng-model="data.message" /> {{data.message + " world"}} </div> </div> function FirstCtrl($scope) { ...

When creating a database for items, which option is more beneficial: using scriptable objects or storing the data in XML

Hey everyone, I've been toying around with the concept of developing an item database. I'm curious to know which option you think would be more practical and user-friendly. If anyone has a list of pros and cons for either, please share them with ...

Data in ng-repeat is only displayed once the node-webkit window is manually moved

Currently, I am developing an Angular application in node-webkit to utilize functionalities like accessing the file system and desktop notifications. In my Angular service, named FileService, I have a method that utilizes fs.readdir() to read files from a ...

Manipulating nested JSON using nested MySQL queries in Node.js and ExpressJS

I am retrieving data from a MySQL database using Node.js and Express.js, aiming to structure it into nested JSON. This is the desired format for the JSON object: [ { "id": 1, "countryName": "USA", "populati ...