Showing nested JSON data in ng-repeat

Currently, I'm struggling to understand how to access nested JSON and show it on a page using Angular. For instance, consider the JSON structure below where I want to display connectivity products under portfolio using ng-repeat...


{
"addons": [
    ...
],

"attributes": [     
    ...
],
"portfolios": [
    {
        "connectivity": [
            {
                "product-1": {
                    "label": "product-1",
                    "description": "Description in here"
                }
            },
            {
                "product-2": {
                    "label": "product-2",
                    "description": "Description in here"
                }
            }
        ]

    }
]

}

I've attempted two different approaches so far.

$scope.listOfProducts = allProducts.data.portfolios.connectivity;

and in the ng-repeat

ng-repeat='product in listOfProducts.portfolios.connectivity'

If you could advise on the correct method to iterate through and display the 'connectivity' products with ng-repeat, I would greatly appreciate it. Thanks!

EDIT:

I revised the JSON like this...


{
"addons": [
...
],

"attributes": [     
    ...
],
"portfolios": [
{
    "connectivity": [
        {
                "label": "product-1",
                "description": "Description in here"
        },
        {
                "label": "product-2",
                "description": "Description in here"
        }
    ]
}
]

However, I'm still unable to utilize ng-repeat for displaying the products in connectivity.

$scope.listOfProducts = allProducts.data.portfolios.connectivity

Answer №1

Given that listOfProducts is already assigned to the connectivity array, you simply need to use

ng-repeat="product in listOfProducts"

<div ng-repeat="product in listOfProducts">
  {{product.label}}
</div>

Update: It appears that your array structure is somewhat irregular, as you are creating a property named product-[index] for each item. Are you able to modify the data being returned? Ideally, your array should just contain objects like this:

"connectivity": [
    {
        "label": "product-1",
        "description": "Description goes here"
    },
    {
        "label": "product-2",
        "description": "Description goes here"
    }
]

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

Having trouble with the repeat-item animation feature not functioning correctly

Take a look at this Plunker, where the animation for adding an item only seems to work properly after an item has been deleted from the list. Any suggestions on how to resolve this issue? Here is the CSS code: .repeat-item.ng-enter, .repeat-item.ng-leave ...

The HSET command in the Redis client for Node.js is not working

I have been developing a DAO (data access object) for the project I am currently working on, which acts as an abstraction of a redis database. Below is the code relevant to my upcoming query: var redis = require("redis"); var _ = require("underscore"); va ...

Guide on merging the root route with child routes using react router v6

When a user visits "/", I want it to automatically redirect them to "/todo", but this functionality is not working as expected. let router = createBrowserRouter([ { path: "/", element: <Layout />, children: ...

Ways to refresh a page after clicking a button inside the modal box

As a beginner in PHP and JavaScript, I am facing an issue with refreshing the page view_create_journals.php when clicking on the change button in the modal. I have added a function to the change button but it doesn't seem to be working. I'm reall ...

Combining load and change events in jQuery at the same time

Often times, I find myself needing to attach a behavior to an element both after it has loaded and after a specific event has been triggered (such as "change"). I believe the most efficient approach would be to combine these actions in one line: $('# ...

Utilizing JQuery's $(document).ready() function following a window.location change

I'm having trouble getting a JavaScript function to run after being redirected to a specific page like "example.com" when the DOM is ready for it to work with. Unfortunately, it seems that $(document).ready() is running before "example.com" finishes l ...

The AngularJS 2 application reports that the this.router object has not been defined

My function to sign up a user and redirect them to the main page is implemented like this: onSubmit(){ this.userService.createUser(this.user).subscribe(function (response) { alert('Registration successful'); localStor ...

Utilizing the $skip parameter in the SharePoint 2013 RESTful API

Excuse my lack of experience with REST, as I am new to it. Currently, I am utilizing SP2013 Odata (_api/web/lists/getbytitle('<list_name>')/items?) in order to retrieve the contents of a list. This particular list contains 199 items, so I ...

Is it Better to Transform JSON Data into a Contract or a Class

Is there a tool or software that can analyze a sample JSON response and create a serializable class or contract? I am struggling to convert a moderately sized JSON structure into a contract, but I have access to a sample response. The JSON response inclu ...

Developing an Angular filter using pipes and mapping techniques

I am relatively new to working with Angular and I have encountered a challenge in creating a filter for a specific value. Within my component, I have the following: myData$: Observable<MyInterface> The interface structure is outlined below: export ...

Are you able to locate <td>s with identical classes using just a portion of the string?

There are multiple classes in the <td>s of my table. I am looking to identify each <td> that contains a specific string. For instance: <table> <tr> <td class="hello there">foo</td> <td class=" ...

Send the output of MPDF back to the browser by utilizing JSON in combination with ExtJS

I am currently using mpdf to generate a PDF report in my PHP code. I have successfully been able to save the PDF file and view it by using Output($pdfFilePath), but now I need to send it back to the browser using JSON without saving it on the server. To ac ...

Tips for passing a timestamp to a Postgresql DB using a Button in a Form instead of a traditional rails time_select box

I am currently developing a CAD App in Rails 4 with Ruby 2. The goal is to provide users with a button on the screen to log an on-scene time and clear scene time, especially since most users will be using touch screen computers. Instead of using the defaul ...

Send form using AJAX with a callback function

I need help figuring out how to submit a form when a captcha is clicked. I attempted to use my own jQuery function, but unfortunately it's not working. Could someone please take a look at my code and let me know what's wrong with it? Javascript ...

Converting Python dictionary to JSON format

As I am still new to Python programming, please excuse any mistakes I may make I'm attempting to create a json file using 2 dictionaries and write the output to the file with the code provided below on Windows import json import sys import string f ...

React components need to refresh after fetching data from an API

I am currently working on a React application using TypeScript and integrating JSONPlaceholder for simulating API calls. I have successfully set up everything I need, but I am encountering an issue with re-rendering components that display response data fr ...

Express: Every declaration of 'user' must have the same modifiers

In my application, I am utilizing both express and passport. Within these packages, there is a user attribute within the Request interface. Currently, the express package has a user attribute in the request object, such as req.user, but no additional prope ...

Discover the method for measuring the size of a dynamically generated list

I'm currently working on a chat box that displays messages as a list. One issue I'm facing is that when I click on the start chat button, the chat box opens but the length of the list always remains zero. How can I resolve this problem? $(docu ...

Idle Time in Nextjs - Making the Most of D

I've been experiencing a significant delay of around 6 seconds when refreshing my Next.js platform. As part of my debugging process to identify the root cause of this issue, I uncovered that approximately 5 seconds of this time is classified as idle. ...

Displaying angularJS ui-grid columns in a lazy manner

Is there a way to efficiently load columns as needed? I have a large dataset with 5k columns and 100k rows. My framework is angularjs 1.5.7 along with angular-ui-grid ^3.x. The grid performs well with 100k rows and 100 columns, but when trying to load ove ...