What is the best method for importing data into an array using AngularJS?

Check out the Plunker link I have shared. Can you help me identify any mistakes?

<a href="https://plnkr.co/edit/3VryaPGtgPRD6Nn8zx7v">Click here to visit the Plunker page</a>

Answer №1

take a look at this

let myApp = angular.module('myApp', []);
myApp.controller('myController', function ($scope, $http) {
  $scope.list = [
    {'id':1,'name':'Orange','price':50,'qty':2},
    {'id':2,'name':'Banana','price':15,'qty':1}
  ];
  $scope.processData = function(){
    data=$scope.list;
    alert(data);
  };
});

HTML code:

<!DOCTYPE html>
<html ng-app="myApp" ng-controller='myController'>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <form >
    <table border="1">
      <tr>
        <td>ID</td>
        <td>Product Name</td>
        <td>Price</td>
        <td>Quantity</td>
        <td>Subtotal</td>
      </tr>
      <tr ng-repeat='item in list'>
        <td>{{item.id}}</td>
        <td>{{item.name}}</td>
        <td>{{item.price}}</td>
        <td>{{item.qty}}</td>
        <td><input type="text" ng-init="{{item.SubTotal = item.price * item.qty}}" name="item.SubTotal" ng-model="item.SubTotal" /></td>
      </tr>
    </table><br>
    <input type="submit" ng-click="processData()" />
    </form>
  </body>

</html>

Answer №2

Make sure to click on the latest plunker link provided, where you can make changes to the object. Any newly updated objects will automatically be added to the table.


Latest Plunker Update

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

Looking for assistance with aligning UL elements in CSS using absolute positioning for a dropdown effect

I'm currently working on implementing a language switching feature on this website. The concept involves using a SPAN element that reveals a dropdown box (based on UL) containing a list of available languages when hovered over. Below is a preview of t ...

Frame Tweet Integration

Attempting to create an iframe modal with a Twitter share source. <iframe src="https://twitter.com/share" class="tweetFrame"></iframe> The current setup is not functioning properly, resulting in a blank page. Is there a workaround to ensure t ...

Steps for changing text box border to red upon validation failure

I am struggling to change the textbox border color to red when validation fails in my AngularJS application. I would appreciate any guidance on how to achieve this. Thank you. <%@ page language="java" contentType="text/html; charset=ISO-8859-1" ...

The text refuses to line up correctly

I am having trouble aligning my text to the right: #login_status { font-size: 1.2em; text-align: right; display: block; float:right; } Here are the relevant CSS styles: #logo { ...

What could be the reason behind the null return value from $request->get()?

When sending a post request from AngularJS form to Laravel, I encounter an issue with retrieving data using $request->get() method. Here is the AngularJS form: <input type="text" ng-model="app.person.firstName"> <input type="text" ng-model="a ...

Custom hover title to transform table into grid

I'm currently working on creating an HTML table and integrating it with the following code: tableToGrid('#grid', {cmTemplate: {sortable:false}}); The original structure of my HTML table is as follows: <tr><th>Month</th>& ...

Show HTML code inside a text box

I have a text box that I populate with data from a Json response like this: <div class="gadget-body" style="height:100px"> <label>{{ textData}}</label> </div> Now, the Json response contains HTML code with <p> and < ...

What is the best way to align the ul, li, and span elements in a single row?

To display the 'previous' on the left side of the list item and the 'next' on the right side, aligned in a single line, how can this layout be achieved? <ul style= 'list-style-type: none;' class="filter1"> <li&g ...

Issues with AngularJS checkbox input failing to register properly on mobile devices?

Inside the ng-repeat, there is an input checkbox structured like this: <div class="provisions"> <label ng-repeat="(key, value) in data"> <div class="innerProvision"> <input class="provisionCheck" type="checkbox ...

What steps do I take to resolve the error message "npm ERR! code1"?

While exploring some open-source projects to learn, I encountered an error after running npm install in the terminal to download packages. It seems that there are some missing packages, and I couldn't figure out the root cause of the error. Initially, ...

Trouble with displaying image in img src in Angular?

I just uploaded an image using nodes and angular. Now, when I try to view the uploaded images from my local disk, the following code is not displaying the image file: <img ng-src="my location/file.png"> What am I missing here? Do I need to set some ...

The size of the elements inside a div should be proportional to its parent div

I am struggling with sizing elements within a div. I have set the max-width to 40% and max-height to 25%, and inside is an image that I want to be 80% of its parent div. Here is the code snippet for reference: <div className="inputbox-container&qu ...

Data is not being stored in Parse

I am currently facing a challenge while working with Parse for Javascript: When users sign up, along with their username and password, I also need to save their first and last names in Parse. However, at the moment, only the username and password are bein ...

Troubleshooting incorrect data display in AngularJS using ng-repeat

Being a newbie in the world of JavaScript, AngularJS, and Parse, I am eager to learn. If there are any mistakes in my approach, please do point them out as I aim to gain as much knowledge as possible. I have been given an assignment that requires me to ut ...

Hovering over the top menu items in AngularJS will reveal dropdown submenus that will remain visible even when moving the cursor

I am facing an issue where my top menu has links that display a dropdown of additional menu items upon hovering. I have attempted to use onmouseover and onmouseleave events to control the visibility of the sub menu. However, I have encountered a problem ...

Angular calendar displaying days and dates in a Gantt chart

I am currently navigating the world of AngularJS and I have implemented an Angular Gantt chart from this repository https://github.com/angular-gantt/angular-gantt. However, I noticed that the chart displays dates but it does not display days (Su, Mo, Tu, e ...

To align a div or text to the right using inline-flex, simply

I am facing an issue with aligning my animated links to the right. Currently, I am using display: inline-flex, which works well but doesn't align the links properly. I have tried using float: right for alignment, but I feel there must be a better way ...

Place a paragraph element within the footer section

I'm having trouble aligning the <p> vertically in the footer. I've attempted to use vertical-align:middle; and margin-bottom:10px; for the p element, but it doesn't seem to be working as expected. Code can be found here: http://jsfidd ...

Ways to restrict input text to a specific set of values

When using an input text form, I need to ensure that users only insert values ranging from 1 to 10. However, my attempts to utilize a mask for customization have resulted in allowing values higher than 10. How can I restrict the input to only be allowed b ...

AngularJS is encountering a 415 error due to an unsupported media type

Spring code @RequestMapping(value="/users",method=RequestMethod.POST,headers = "content-type=application/json;application/x-www-form-urlencoded; charset=UTF-8") public @ResponseBody String createNewUser( @RequestBody @Valid User user) { System.out.pri ...