Best practice for connecting ng-model in ng-repeat

I have the following list:

"List": {
"lorem": 127,
"ipson": 5.5,
"dolor": 29,
"sit": 19}

Next, I am utilizing the ng-repeat code below to construct a table with input fields:

<table>
        <tr ng-repeat="(item, weight in settings.list">
            <th>
                <input ng-model="item"></input>
            </th>
            <th>
                <input ng-model="weight"></input>
            </th>
        </tr>
</table>

My main goal is for the ng-model to update the parent scope, but currently, I am unsure of how to achieve this.

Answer №1

If you're looking to create a list structure, it should be structured as follows:

list : [
  {
   name : "lorem",
   weight : 127
  },
  {
   name : "haha",
   weight : 12
  }
];

After defining your list, you can display it in a table format using AngularJS:

<table>
        <tr ng-repeat="item in settings.list">
            <th>
                <input ng-model="item.name"></input>
            </th>
            <th>
                <input ng-model="item.weight"></input>
            </th>
        </tr>
</table>

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

NodeJS is capable of handling a limited number of requests at a time

Utilizing jQuery to send requests to a local server has been causing some issues. After sending approximately 4-7 requests, the port stops working without any visible error. Eventually, after a few minutes, some of the requests are successfully sent to the ...

Having trouble updating dropdown value with Reactjs

Currently, I am diving into the world of Reactjs/Nextjs and facing a challenge with modifying dropdown values within the update module. Despite my attempts with the code below, I haven't been able to make it work smoothly. const Post = function(prop ...

Limiting the length of numbers in Material UI

Is there a way to restrict user input to only numbers with a maximum length of 3 in Material UI? <TextField id="score" label="score" className={classes.textField} name="totalScore" margin="normal" defaultValue={score} /> We specifically ...

Personalized animated Reactflow Connection Lines

My goal is to develop a personalized animated connection lines in reactflow, rather than using the default dashed line that appears when the animated: true prop is applied. I am aware that we can customize the styling by using the following code snippet: ...

Organizing into distinct categories using Angular

I'm a beginner in the world of Angular and programming, seeking guidance on how to learn. I have an HTML page with 5 tabs: "Who," "What," "Where," "When," and "Events." The code snippet below showcases my current setup. Can anyone provide assistance o ...

Using AngularJS to access the properties of a header within a $http request

As I navigate through the github API's pagination documentation, I am attempting to retrieve event items and extract the Link header (as recommended) in order to construct the pagination. However, I am facing difficulty in understanding how to work wi ...

Utilizing the output from a console.log in a webpage

Although the function I created is functioning properly and successfully outputs the value to my terminal onSubmit, I am facing difficulty in understanding why this code isn't updating my html. router.post('/index', function(req, res, next) ...

Switch the div's class after it has faded out

I am facing an issue with a hidden div that I want to make visible for 5 seconds when a button is clicked, and then hide it again. This is the code I used: $("#errorMessage").removeClass("hide").delay(5000).fadeOut("slow", function () { $ ...

Adjust the $scope variable depending on the size of the screen

Currently, I have a sidebar that collapses based on the value in $scope, specifically when $scope.open is set to true. However, I've noticed that if the menu is left open and viewed on mobile devices or small windows, it can look quite messy. To addre ...

Append a constant string to the conclusion of the route parameter

Using React Router v6.4.1, I am aiming for a consistent conclusion to a series of dynamic routes. Specifically, I want my product detail routes to always end with "-product". For example, if the path is "/shaver-900-product", it should activate my Produc ...

The functionality of passing an ID in Bootstrap Modal is not functioning as expected

I'm facing an issue with passing an ID to my modal. My goal is to have the details of an event displayed in the modal when the corresponding link (which represents the event) is clicked. However, I'm struggling to retrieve the ID and show the ev ...

Encountering Rendering Issues with EJS Post HTML Conversion

After working on a much larger project for over a month, I'm now six hours into troubleshooting and everything is starting to blend together. Prior to switching to EJS, everything was working perfectly. I'm not looking for someone to solve the ...

There seems to be a glitch in my JavaScript for loop as it is not iterating for the correct amount that it should

It seems like my for loop is not always iterating 7 times as intended. Sometimes it runs with 5 iterations, other times with 4 or 3. This is the JavaScript code I am using: var start = new Date().getTime(); var end = new Date().getTime(); function timeT ...

Running a JavaScript function directly in the browser's address bar with GWT

Attempting to run Javascript in my web application by entering the following in the browser URL/address bar: javascript:window.alert('test');void(0); Despite this, the alert box fails to display. Is it possible that the application is in DevMod ...

The functionality of app.get('') is malfunctioning in Node.js when it comes to handling query parameters

I'm currently working on updating my conversation application to handle new routes that accept parameters and pass them along to the client side. However, I'm facing an issue with the .get() method not rendering the HTML as expected. 'use s ...

Utilizing several carets in a single or multiple text areas and input boxes

Just a quick question... Can a textbox have two carets simultaneously, or can we have two separate textboxes both focused at the same time? I am aware of simulating this using keydown listeners but I'm specifically looking for visible carets in both ...

Running a cfquery in a cfc and passing parameters through AJAX

I am currently setting up a system to retrieve data from my ColdFusion database using JavaScript. However, I am encountering an error and unsure of its cause since I am relatively new to CF. The specific engine I am utilizing is ColdFusion MX 7. Below is ...

Mismatch between the format and extension of an HTML table when exporting to Excel

I've been working on a function that converts an HTML table into an Excel document. Unfortunately, when I try to open the file in Excel, I receive an error message that says: The file format and extension of 'something.xls' don't mat ...

Using the fs module in a React Native application

Currently, I am facing a challenge in importing TinyDB into an expo project. The issue lies with fs, as Expo does not support it due to its third-party file system nature. I attempted using react-native-fs as an alternative but I am unsure about how to pr ...

What is the best way to convert an array of data into a dataset format in React Native?

Within my specific use case, I am seeking to reform the array structure prior to loading it into a line chart. In this context, the props received are as follows: const data = [26.727, 26.952, 12.132, 25.933, 12.151, 28.492, 12.134, 26.191] The objective ...