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

Deciphering the intricacies of the http request

I encountered an issue while trying to send a POST request using jQuery AJAX. Upon making the request, I received the following error: XMLHttpRequest cannot load. Response for preflight has invalid HTTP status code 403 Now, I am unsure if the mistake i ...

Passing the JSON object located at the selected index within a listview to the next activity in my android application

Hello everyone, I need some help with a coding issue I'm facing. I have been searching for a solution to this problem but haven't been successful so far. In theory, I know that I should use i.putExtra("jsonArray", jArray.toString()); in my inte ...

Caching a large JSON file on both the server and client side

My task involves generating and delivering a rather large JSON file to users, clocking in at around 400 KB. This file is essentially the combination of data from two tables, and it's likely to grow in size as time goes on. The purpose of this JSON fil ...

JavaScript special character encoding techniques

I'm trying to create a function to remove special characters in my JavaScript code. However, whenever I try using chr(46), it throws a syntax error. Does anyone have any suggestions on how I can successfully implement chr(46) in my JS code? storageV ...

Transforming a list into Json format within Robot Framework

Upon invoking a specific Get Regexp Matches function, I received the following list: ['{"result": 1, "error": { "namespace": "global", "reason": "unauthorized" } }'] While trying to verify values using the method below: Should Be Equal ${res ...

Is it possible to locate/create a JSON keyname in a jQuery $.post function?

Currently, I am diving back into the world of Ajax after a long break. At this point, I have created a page that is able to fetch a dynamic number of elements (initially ten, but this can change), and populates each of the ten divs with relevant text. In ...

Exploring the enhanced capabilities of FeathersJS by integrating express-babelify-middleware

Attempting to integrate express-babelify-middleware with FeathersJS, an error message appears in the browser console: The error reads: ReferenceError: main_run is not defined This indicates that babelify may not be functioning correctly or I might be u ...

Using an if statement following the iteration of a JSON object in a React Native application

I am currently working on a weather app using react native as a fun project. I have set up an API to fetch weather data in JSON format. My goal is to show the hourly weather details based on the current time of the day. export default class App extends ...

"Make sure the last if statement is always the one being executed

I have been using angularjs to develop a mini quiz application. I created 4 if statements, but for some reason, the last condition is always executed even if no answers have been selected. Why does $scope.makeup consistently display You should have makeup ...

The issue of generating PDFs in PHP/Ajax encountering a timeout

I have a script written in PHP/ajax/jquery that generates documents containing values from a database. However, I am facing an issue when attempting to generate a large number of PDFs and Word files in a short amount of time. For each element in the array ...

Rephrase the ajax call and the data retrieved

I'm struggling to find a solution for writing this code snippet without using async: false,. var imageX; var groupX; $.ajax({ type:'GET', url:'php/myphp.php', dataType:'json', async: false, success: ...

Using JSONP in AngularJS can be a powerful tool for

My goal is to extract data from my Database and integrate it into my Angular.js application. To achieve this, I have created a PHP file that selects the necessary data. I have come across information stating that I need to utilize jsonp in order to succes ...

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 ...

How to verify if an object is empty in an AngularJS expression

I need to display either a Login or Logout button based on the value of a $rootScope variable. Currently, only the Logout button is showing up in the li tag below. I have specific actions that should occur after certain events: After Logging In:- $root ...

How to effectively inject moment.js dependency into AngularJS?

In my app.js file, I've defined my app module like this: var myApp = angular.module('myApp', ['angularMoment']); Next, in my controller, I'm trying to use the moment() function: myApp.controller('myComtroller', [& ...

Combining strings within a string after a specific word with nested Concatenation

In a given string variable "str," I am looking to concatenate another string between "InsertAfterMe" and "InsertBeforeMe". str="This is a string InsertAfterMe InsertBeforeMe" s1="sometext" s2="soMoreText" aList=[1,2,3,4,5] The concatenated string shoul ...

The act of receiving becomes ineffective when it was intended to be functional - Nextjs/JavaScript

When using nextjs, I encountered an issue while trying to map my array to getstaticpaths for generating getstaticprops. Every time I attempted to map the result, I received an error stating 'mycatagoriesis not a function'. Below is a snippet fro ...

Prevent anchor jumping caused by popstate event in Safari

This situation is really testing my patience. When navigating within the same page using anchors, the browser automatically takes you back/forward to the location of that link in your history when popstate is triggered. One might think that you could prev ...

Comma Filtering in Ag-Grid

I am currently working with ag-Grid, and I have encountered an issue when filtering my data. Specifically, when I filter the price column, it only recognizes numbers with dots and not commas. Link: https://plnkr.co/edit/LDdrRbANSalvb4Iwh5mp?p=preview To ...

Complete my search input by utilizing ajax

It's only been 30 minutes since my last post, but I feel like I'm making progress with my search posts input: I've developed a model that resembles this: function matchPosts($keyword) { $this->db->get('posts'); ...