Utilizing Angular.js to extract data from a deeply nested array of objects in JSON

Hello, I am currently learning about Angular.js and working on developing a shopping cart. In this project, I need to display an image, name, and cost of each product for multiple tenants. Each tenant has an array called listOfBinaries which contains listOfMerchandise. My issue is that I need to show the name from the tenants, the image from listOfBinary, and the cost from listOfMerchandise. After parsing the JSON data retrieved from an AJAX call to the REST URL, my page appears empty when running the application. Can someone please provide assistance? Below is the JSON data obtained after making the API call:

{
"_links": {
    "search": {
        "href": "http://localhost:8080/sportsrest/tenants/search"
    }
},
"_embedded": {
   // JSON data continues...
}

My directives.js file contains the following code snippet:

 // Code snippet for Ajax call in directives.js file
// Getting the above JSON data from the API call

This is a snippet of my HTML page where I want to display the product details using Angular.js:

<!DOCTYPE html>
 < html ng-app="myApp">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>

   </head>
   <body>
    <div ng-app="myApp" >
    <div  ng-controller="items_display">
    <div  ng-repeat="item in carts._embedded.tenants">
    <div type="text" class="item_name" value={{item.name}}  > 
    <div  ng-repeat="item in carts._embedded.tenants.listOfBinary">
     <img  class="shop_img" ng-src="{{item.fileLocation}}"  ng-style="{'width':'100px', 'height':'100px'}" /> 
     <div  ng-repeat="item in carts._embedded.tenants.listOfBinary.listOfMerchandise">
      <div type="text" class="item_cost" value={{item.rate}}  > 
    </div>  
      </br>
     </div>
    </div>
    </div>
</body>

If anyone can provide guidance on how to successfully display the product details on the HTML page using Angular.js, it would be greatly appreciated. Thank you in advance.

Answer №1

Looks like your markup needs some fixing, take a look at the plunker I created using your data and markup

http://plnkr.co/edit/jGCm6nO9S4hlNxLCyrSy?p=preview

<body>
  <div ng-app="myApp">
    <div ng-controller="items_display">
      <div ng-repeat="tenant in carts._embedded.tenants">
        <div type="text" class="item_name">{{tenant.name}}
          <div ng-repeat="binary in tenant.listOfBinary">
            <img class="shop_img" ng-src="{{binary.fileLocation}}" ng-style="{'width':'100px', 'height':'100px'}" />
            <div ng-repeat="(key, value) in binary.listOfMerchandise[0]">
              <div type="text" class="item_cost">{{key}}: {{value}}
              </div>
              <br>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

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 is the importance of always catching errors in a Promise?

In my project, I have implemented the @typescript-eslint/no-floating-promises rule. This rule highlights code like this - functionReturningPromise() .then(retVal => doSomething(retVal)); The rule suggests adding a catch block for the Promise. While ...

What could be causing me to receive no results?

Currently, I am expanding my knowledge in JavaScript, Ajax, and NodeJs. My current project involves creating a webpage that can display a string retrieved from the server. The server-side code is as follows: var express = require('express'); v ...

Add some TD(s) after the td element

The HTML code I currently have is as follows: <tr> <td class="success" rowspan="1">Viability</td> <td data-rowh="-Checksum">Viability-Checksum</td> </tr> <tr> ...

After the URL of the window was updated, the local storage was automatically cleared

function makeAjaxCall(){ ............... ............... success:function(response){ localStorage.setItem("token", response['token']) window.location.href="https://www.example.com/profiler/" } } The code snippet above is fo ...

Obtain the current name of the Material UI breakpoint

Looking for a MUI function called MaterialUIGiveMeCurrentBreakPointName that can help me execute an action in a component like so: const currentBreakPointName = MaterialUIGiveMeCurrentBreakPointName() if(currentBreakPointName === 'myCustomBreakPointN ...

Incorporate a map (using leafletjs or Google Maps) as a subtle backdrop

I am currently working on a one-page website and I would like to include a map as a background behind the "contact" section. The map can be set to float, draggable, or positioned at the back. I have experience using both the Google Maps API and LeafletJS, ...

ASP.NET ensures that the entire page is validated by the form

Is it possible to validate only a specific part of the form instead of the entire page? Currently, when I try to validate textboxes on the page, the validation is applied to all textboxes. Here are more details: https://i.stack.imgur.com/eowMh.png The c ...

Angular.js enables the ability to display views from several partials that are loaded dynamically

My goal is to create a view composed of multiple partials that are loaded dynamically based on the content type. While I am new to angular.js, my current approach in the controller involves: $(elem).html(string_with_src); $compile(elem.contents())($scope) ...

Utilizing Typescript for manipulation of Javascript objects

Currently, I am working on a project using Node.js. Within one of my JavaScript files, I have the following object: function Person { this.name = 'Peter', this.lastname = 'Cesar', this.age = 23 } I am trying to create an instanc ...

Is there a way to easily open the RSS link XML Element in a separate browser tab or window?

I have been exploring RSS and creating titles with links. However, when clicking on the link it opens in the same window. I would like it to open in a new window instead. Can someone please advise me on how to achieve this? <a href="http://www.google ...

The property 1 cannot be added because the object is not extendable in React

Does anyone know what is causing the following issue? I am unable to insert a new object into a key object within my arrays of objects. For example, when I try to insert a new email at index 1 in the 'emails' array, it throws an error stating "ca ...

Difficulty recognizing sessions in production for a self-hosted Next.js application using Clerk Dev Auth

Having trouble finding the next step in debugging as I couldn't resolve the issue on Clerk's Discord or GH Issues. It seems like it might be a Next.js problem rather than a Clerk one? I am currently running a self-hosted next.js app in a docker ...

Guide on processing a hefty JSON file by rounding decimals to the nearest integer and calculating the average of y values when there are duplicate x values

I am currently exploring ways to efficiently filter and parse through extensive JSON data sets. My main goal is to round the x values to the nearest integer. In cases where there are duplicate entries, I aim to calculate the average of the y values while ...

What is the deal with mapstatetoprops function in Redux?

This is the index.js file import {Provider} from 'react-redux' import {createStore} from 'redux' import rootReducers from './rootReducers' const store = createStore(rootReducers) ReactDOM.render( <Provider store = {stor ...

Using Python, a key-value pair in a JSON object can be created with the value

I am currently working on extracting json key values using python scripting. Initially, the json data is stored in a string variable and then converted into a dictionary format. data='{"enc_column": "5", "Delimiter": &qu ...

Using AngularJS to show content based on a callback function

I'm a beginner in angular and it seems like I might be overlooking something. For the registration form, I need users to provide their location. Depending on whether they allow/support navigator.geolocation, I want to display a drop-down menu for cho ...

Statistics Sweden SCB API call was made, but unfortunately, no data was retrieved

I am having trouble accessing the actual values of the data in my table, as all I can see is the dates in the JSON output generated. The specific link I am using is: "http://api.scb.se/OV0104/v1/doris/en/ssd/START/FM/FM5001/FM5001A/FM5001SDDSPM" ...

Using jQuery, it is possible to eliminate a div element without affecting its contents

<div class="a"> <div class="b"> <ul> <li>Element A</li> <li>Element B</li> </ul> </div> </div> How can I eliminate div class="b" solely? I require the presence of div a, u ...

Managing session timeouts during an AJAX call triggered by the Kendo ComboBox read action

Looking for a solution to handle session timeout specifically with kendo combo-box implementation? Here is the HTML code snippet for my kendo combobox: @(Html.Kendo().ComboBoxFor(model => model.PropertyName) .AutoBind(tru ...

Wordpress AJAX request results in a value not found

** I have added more details, thank you for your assistance so far I am in the process of implementing an AJAX search functionality on my Wordpress site to filter properties based on type, location, and status. Being a novice at AJAX, I have been followi ...