Implementation of arrays with dynamic textboxes insertion

Looking for a dynamic array output like this:

tableNames = [
    ["string1", "string2"...],
    ["string", "string"...]
];

Looking for assistance with AngularJS code design to achieve this structure, where the values of the strings are entered through text boxes and each array is dynamic. Can anyone provide guidance?

Answer №1

It can be challenging to use ng-repeat with an array of arrays in your tableNames. Consider using an array of objects instead.

<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript">
var app=angular.module("myApp",[]);

app.controller("myCTRL",function($scope){
$scope.items=[{firstname:'ArunMozhi', lastname:'Varman'},{firstname:'Karikala', lastname:'Cholan'}];
      
      $scope.tableNames = [
    ["string1", "string2"],
    ["string", "string"]
];
 $scope.add = function(){
 $scope.items.unshift({firstname:'', lastname:''}); // you can use push         also
 }

});
</script>

<body ng-app="myApp" ng-controller="myCTRL">

<br><br>
<div>
<form name="addForm" novalidate>
    <button ng-click="add()" ng-disabled="addForm.input.$invalid">Add</button><br><br>
    <div ng-repeat="item in items">
<input type="text" name="input" ng-model="item.firstname" ng-required="true">
    <input type="text" name="input" ng-model="item.lastname" ng-required="true">
<br><br>
      </div>       
</form>

</div>
{{items}}
  
  <br><br>
  
  Your Result:-
  
  <div ng-repeat="item in tableNames">
<form novalidate>
    <input type="text" ng-model="item[0]">
    <input type="text" ng-model="item[1]">
<br><br>
</form>

</div>
  {{tableNames}}
</body>
</html>

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 best way to validate a particular class in javascript?

Need help checking if a specific id has a particular class. Unsure of the process? Here's the code snippet where the attempt at checking the id for a specific class is visible within the homeTransition function. function homeTransition() { ...

Parsing JSON with jQuery in Grails is a seamless process that allows for efficient

I've implemented an ajax function that successfully sends data to my controller. var ids = grid.jqGrid('getGridParam','selarrrow'); if (ids.length>0) { var names = []; for (var i=0, il=ids.length; i < il; i++) { ...

When you hover over the page, the content shifts to reveal a hidden div

Trying to figure out how to show additional content when a photo is hovered over without shifting the rest of the page's content placement? Looking for alternative solutions rather than using margin-top: -22%. Here's a link to the website in que ...

Tips for styling the json response received from a servlet with jquery ajax

I am attempting to display a list of users returned from a servlet using jQuery ajax. The first script block is functioning well, successfully presenting the list of users in a formatted manner but experiencing issues passing form parameters such as text a ...

Parsing a JSON document containing nested arrays of data

I am encountering an issue with deserializing the following JSON string: {"error":null,"id":1234,"result":[[["config.param1","111"],["config.param2","1222"]],"Config System",1234]} My structure is as follows: Public Structure stuConResponse Dim [Er ...

There is an array present with data filled in, but unfortunately, I am unable to retrieve specific elements

As I work on my WordPress 4.7.2 website, I find myself making an AJAX call. The PHP function handling this call returns an array using wp_json_encode(). When I view the data array in the success callback of the AJAX function, everything looks just as expec ...

Utilizing .isDisplayed() in conjunction with .each() in ProtractorJS for Angular: A guide

Currently, I am working on setting up a test within my Angular application. The goal of this test is to click on an element and check if a specific object is displayed. While I believe the code provided below should work, I am aware that the isDisplayed( ...

The error message states: "It is not possible to destructure the property 'createComponentInstance' of 'Vue.ssrUtils' as it is undefined for nuxt and jest."

I have been working on integrating the jest testing framework into my nuxt project, but I am facing a major obstacle. I am struggling to test a simple component and haven't been able to find a solution yet. If anyone has encountered the same issue, co ...

Ways to verify the identity of a user using an external authentication service

One of my microservices deals with user login and registration. Upon making a request to localhost:8080 with the body { "username": "test", "password":"test"}, I receive an authentication token like this: { "tok ...

Calculate the total number of rows in my table and display it in the console using AngularJS

Currently, I am working on a web application that includes a table and a checkbox. When the checkbox is checked, I want to display the total number of rows in the table. Here's an example layout: <table> <thead> <tr> <td& ...

Leverage the Node Short ID library in conjunction with Angular 6 using TypeScript

I attempted to utilize the node module within an Angular 6 typescript environment. Step one: npm i shortid Within my TypeScript class: import { shortid } from 'shortid'; let Uid = shortid.generate(); However, I encountered an error stating ...

Does Vuejs emit an event when a specific tab becomes active in boostrap-vue?

I am looking for a way to display and hide a section on my page when a specific tab is active, and close it when the tab is inactive. I have tried using the forceOpenSettings and forceCloseSettings methods for opening and closing the div. Is there an event ...

The Wikipedia API is unable to be loaded using the XMLHttpRequest

I have encountered this error before on this platform, and although I managed to fix it, I am seeking a more in-depth explanation of the solution. For a project where I am learning, I decided to create a Wikipedia Viewer application. The first step was to ...

Tips for effectively assessing user inputs within a secure sandbox environment

I need my application to process an expression provided by a user from a JSON file, but I want to ensure it runs securely without the risk of malicious code execution. An example expression could be: value = "(getTime() == 60) AND isFoo('bar')" ...

Interact with multidimensional arrays using Vue JS

Is there a way to access properties within objects nested inside multidimensional arrays when using v-for with VueJS? var arr =[{"fruit": {"fruitName": "apple"}, "vegetable":[{"vegetableName": "carrot" }]}]; I am attempting to display it in the following ...

Checking the alignment of celestial bodies for an array of entities

Seeking to implement validation for a form featuring checkbox selections with corresponding number inputs. When a user selects a profession checkbox, they must enter the number of years of experience they have in the input next to it. The array structure i ...

Using Angular Directive to create a customized TreeView

Although I am still relatively new to Angular, I need to make some modifications to a treeview directive that I found on NgModules. The existing code looks promising, but I want to customize it to include the ability to add, delete, or modify items. You c ...

Using a JSON object in HTML directive with AngularJS conditional statement

Having a JSON object that looks like this: { filters: [ {Name: "pork", Active: true}, {Name: "beef", Active: true}, {Name: "chicken", Active: false} ] } An intention to create a SELECT list with th ...

What is the process for verifying a checkbox after it has been selected?

I simplified my code to make it easier to understand const [factor, setfactor] = useState(1); const [nullify, setNullify] = useState(1); const Price = 10; const Bonus = 15; const finalPrice = (Price * factor - Bonus) * nullify; // start ...

A basic problem involving appending content using jQuery

I have encountered a puzzling issue. Whenever I attempt to insert new content into the <div> element using my JS code, it briefly appears and then disappears abruptly. I am unsure of the reason behind this behavior. Is there a way to prevent this fr ...