A guide on how to associate data in ng-repeat with varying indices

Here is the data from my JSON file:

var jsondata = [{"credit":"a","debit":[{"credit":"a","amount":1},{"credit":"a","amount":2}]},
 {"credit":"b","debit":[{"credit":"b","amount":3},{"credit":"b","amount":4},{"credit":"b","amount":5}]},
 {"credit":"c","debit":[{"credit":"c","amount":6}]}]

This is the HTML code snippet:

<div ng-repeat="x in ?????" >  <input>{{ x.amount}}</input></div>

I am looking to display all the "amount" values from the debit records in a single grid as input fields. Additionally, when I update an amount value in the input field, it should reflect in the original JSON data. Can you help me solve this issue? Thank you in advance.

The expected output in the grid would be:

1
2
3
4
5
6

Answer №1

let app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.data = [{"name":"John","age":30,"city":"New York"},{"name":"Jane","age":25,"city":"Los Angeles"}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

<body ng-app="myApp" ng-controller="myCtrl">
  <div ng-repeat="user in data">
    {{ user.name }} is {{ user.age }} years old and lives in {{ user.city }}
  </div>
</body>

Answer №2

You will need to utilize 2 ng-repeats in this scenario.

<div ng-repeat="item in jsonData">
    <div ng-repeat = "element in item.debit">
      <div> {{element.amount}}</div>
    </div>
</div>

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

Receiving an error when attempting to inject the Router in a component constructor without using the elvis operator

Upon launching my app, I desire the route /home to be automatically displayed. Unfortunately, the Angular 2 version I am utilizing does not support the "useAsDefault: true" property in route definitions. To address this issue, I considered implementing th ...

Error handling: Encountered unexpected issues while parsing templates in Angular 2

I'm a beginner with Angular 2 and I'm attempting to create a simple module, but encountering an error. app.component.html import { Component } from '@angular/core'; import { Timer } from '../app/modules/timer'; @Component({ ...

Cherrypy/Chrome: Issue with jquery ajax request remaining pending after several successful requests

My current project involves a Cherrypy server that receives a JSON array from a client via AJAX call. The server then manipulates the array and sends it back to the client. However, I've noticed an issue where after a few smooth requests, the next req ...

The Golang json.decoder can successfully parse requests except for those originating from web browsers

My Go application is encountering issues decoding form data from browsers, but it works fine when using curl and httpie. Take a look at this code: type User struct { Username string `json:"username"` Email string `json:"email"` Password s ...

I'm attempting to render HTML emails in ReactJS

I have been attempting to display an HTML page in React JS, but I am not achieving the same appearance. Here is the code snippet I used in React JS: <div dangerouslySetInnerHTML={{ __html: data }}/> When executed in regular HTML, the page looks lik ...

Can you explain the significance of polyfills in HTML5?

What exactly are polyfills in the context of HTML5? I've come across this term on multiple websites discussing HTML5, such as HTML5-Cross-Browser-Polyfills. Essentially, polyfills refer to tools like shims and fallbacks that help add HTML5 features ...

Change numbers into a comma-separated style containing two decimal points using javascript

I have been working on a JavaScript function to convert numbers into a comma-separated format with two decimal places: Here is my current code snippet: Number(parseFloat(n).toFixed(2)).toLocaleString('en'); The issue with this code is that it ...

Is it achievable to refresh ng-repeats in Angular.js using the current scope data?

I currently have a series of interconnected ul lists in my view that are utilizing jQuery UI: Sortable to allow for drag and drop functionality for reordering items within the list. After making changes via jQuery UI's drag and drop, I update the $sc ...

Issue encountered while trying to run Bower Install: Unable to establish connection with an exit code of #128

I encountered a problem while trying to run bower install. bower ECMDERR The command "git ls-remote --tags --heads HTTPS_LINK to bower-angular-mocks.git" failed with an exit code of #128 After seeking advice from Git / Bower Errors: Exit Code ...

Steps to have index.html display when running the build command in a Svelte project:

Greetings everyone, I'm brand new to using Svelte and have a question that's been on my mind. I recently developed a small app in Svelte that works perfectly fine during development. However, when I run npm run build for production, the output ...

Best method for simultaneously calling multiple routes in Node.js and Express

What is the best approach for handling multiple routes simultaneously in Node.js and Express? For instance, if I have two routes defined as app.get('/', routes.views.index); and app.all('/header', routes.views.header); I want both route ...

Position a component in relation to another component using AngularJS

Utilizing ng-show and ng-hide, I created a descriptive box that appears below text when clicked. However, there is an issue as the description box does not align directly under the text, similar to what is shown in this image https://i.stack.imgur.com/phBh ...

Start the service without the need to include it as an argument

Looking at some older AngularJS code I've inherited, it appears like this: angular .module('MyModule') .directive('MyDirective', []) .controller('MyController', [ 'MyDependency', func ...

What is causing jQuery toggleClass to fail in removing a class?

I have successfully implemented a Skills accordion feature, but I am now trying to add a button that toggles all the skill sections at once. However, I am facing issues with jQuery not correctly adding or removing classes on the .accordion-trigger-all elem ...

Converting Rails application from AngularJS to ERB

I am currently working on integrating AngularJS into my code <button class="btn" ng-click="editUser(user.id)"> <span class="glyphicon glyphicon-pencil"></span>  Edit </button> I need to convert the foll ...

Sending JSON data from an iOS app to a Flask backend

Within my Flask Python web application, I store certain parameters in SessionStorage to later send back to Flask and save this data as a text file. Interestingly, the process functions perfectly on PCs and Android devices but encounters issues on iOS devi ...

Having difficulty extracting data from FormData() object and encountering difficulty sending it through the frontend

Whenever I use Postman to send data, the Title, description, and image are successfully transmitted. This is how my post array looks like: router.post('/', uploadS3.array('meme',3),(req, res, next)=>{ // res.json(req.file.locatio ...

What's preventing my Angular list from appearing?

I am currently developing an Angular project that integrates Web API and entity framework code first. One of the views in my project features a table at the bottom, which is supposed to load data from the database upon view loading. After setting breakpoin ...

Enhancing Chat: Updating Chat Messages in Real-Time with Ember.js and Firebase

I recently started working with ember.js and firebase. Right now, I have successfully implemented a feature to post messages and view them in a list format as shown below: //templates/show-messages.hbs {{page-title "ShowMessages"}} <div clas ...

Vanilla JS method for resetting Bootstrap 5 client-side validation when focused

I'm currently exploring Bootstrap 5's client-side validation feature. However, I've encountered a usability issue with the is-invalid class. After clicking the submit button, this class persists until the correct input is entered. I would li ...