Issues with ng-repeat causing the Angular Editable table to malfunction

<table class="table table-bordered">
    <tbody>
        <tr ng-repeat="playerOrTeam in template.editableTable track by $index">
            <td style="text-align: center;" ng-repeat="playerOrTeamCat in playerOrTeam track by $index">
                <input ng-model="playerOrTeamCat" type="text" class="form-control input-sm">
            </td>
        </tr>
    </tbody>
</table>

template.editableTable contains a multi-dimensional array with standard variables. However, when I modify the value in the input box and check the output of template.editableTable, I do not see the changes reflected. Am I overlooking something obvious?

Adding more details as there have been no responses =\

//Template Class
app.factory('Template', function () {
    var Template = function () {
          /*
          * Public Variables
          */
          this.editableTable = someMultiDimensionalTable;
      }

      /*
      * Functions
      */
      Template.prototype.SeeEditableTableContents = function () {
        console.log(this.editableTable);
      }
 }

//Main Controller
app.controller('MainController', function () {
  $scope.template = new Template();
  //etc
}

Answer №1

In ng-repeat, it is not possible to make direct inline modifications. Instead, you can update an entry in the array using a function.

Here's an example of how you could do this:

$scope.updateEntry = function (index) {
    console.log("Updating entry");
    $scope.data.list[index] = angular.copy($scope.selectedItem);
    $scope.clear();
};

Check out this JSFiddle for a demonstration.

Answer №2

After some trial and error, I managed to make inline modifications using ng-repeat by restructuring my multidimensional table to contain objects instead of just values.

Here is how I updated the table:

<table class="table table-bordered">
    <tbody>
        <tr ng-repeat="playerOrTeam in template.editableTable track by $index">
            <td style="text-align: center;" ng-repeat="playerOrTeamCat in playerOrTeam track by $index">
                <input ng-model="playerOrTeamCat.value" type="text" class="form-control input-sm">
            </td>
        </tr>
    </tbody>
</table>

I found inspiration for this approach on this thread about modifying objects within Angular Scope inside ng-repeat

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

Tailwind Component Grid in Action

I'm trying to arrange a list of JavaScript components in a grid with one row and twelve columns. I want to use only six columns for the actual elements, while having three columns of padding on each side of the grid. My goal is to place three elements ...

Utilizing a library across various files in Node.js

I am looking to integrate Winston for logging in my nodejs express project. Within my main file ( server.js ) I currently have the following code snippet: const winston = require('winston'); winston.level = process.env.LOG_LEVEL winston.log(&ap ...

Locating a user by their ID within a collection in Meteor can lead to some unexpected behavior

I have a requirement where I only want to allow users to insert a document if their email is verified. In an attempt to achieve this, I wrote the following code snippet. Events.allow({ insert: function (userId, doc) { var user = Meteor.users.f ...

Steps for resolving the error message: "An appropriate loader is required to handle this file type, but there are no loaders currently configured to process it."

I am encountering an issue when working with next.js and trying to export a type in a file called index.ts within a third-party package. Module parse failed: Unexpected token (23:7) You may need an appropriate loader to handle this file type, current ...

Display the iframe website without it being visible to the user

Is there a way to load a separate website, such as a Wikipedia article, in an iframe on a webpage without freezing up the whole page when it becomes visible after clicking a "show" button? And if not, how can we display a loading gif while the iframe is ...

What is the best way to establish my permit requirements on a monthly basis?

An employee is only allowed to request up to 3 permits per month. If they need a fourth permit, they will have to wait until the following month. Here is my table structure for permissions: Permissions id (integer), format (text), date_r ...

Loop through the data string in Ajax using a For Loop to populate it

I am currently working on a loop that inserts select tags based on the number of rows. Each select tag will have an ID like selID0, selID1, selID2, and so on. My goal is to call an AJAX function to determine which tag is not selected when the submit button ...

Tips for arranging information in ng-repeat using nested objects within JSON data on AngularJS

Looking to display an array of object properties in an Angular view. Here is the object: $scope._Json = { "foo": { "ItemDimension1": { "Item": "item1", "ItemIndex": 1, "SelectedItems": [{ "C ...

What is the best way to refresh a React ES6 component following an AJAX response?

I'm a beginner in React and ES6, trying to create a search field that fetches data as the user types. I want to make an AJAX call using the fetch API when the user types at least 3 characters in the field. When I run the fetch snippet code in the brow ...

Here's a unique version: "A guide on using jQuery to dynamically adjust the background color of table

I need some assistance with changing the background color of td elements based on the th class. Specifically, I want to target all td elements under the bots class in the HTML code provided below. <table border="1" class="CSSTableGenerator" id="myTab ...

Exploring Vue CLI: Guidelines for updating, deleting, and browsing through all available plugins

After diving into the world of Vue.js, I quickly realized that Vue CLI is essential for speedy development. I got it up and running, created an app, and everything seems to be going smoothly. I decided to enhance my project by adding the Vuetify.js plugin ...

The radio buttons are stuck and not changing their selection

Having a group of radio buttons with the same name, when one is checked, it automatically selects another one in the group. Here is my current code: <input name="a" type="radio"> <input name="a "type="radio" checked> JS $("input[type='r ...

Navigating the world of date pickers: a deceptively easy challenge

Take a look at this fiddle example to get started: http://jsfiddle.net/1ezos4ho/8/ The main goals are: When a date is selected, it should be dynamically added as the input value, like <input type text value="date selected".... Update: <s ...

Using AngularJS to add a third-party module called ngIdle

Below is a controller that I am working with: (function () { "use strict"; var app = angular.module('Demo') .controller('MainController', ['$rootScope', '$scope', '$location', 'curUser',MainC ...

Respond to the initial message within the "if" statement

client.on('message', message => { if (message.channel.type === 'text' && message.channel.name.toLowerCase() == "channel-2" && message.content === "test") { message.react("✅") } ...

Looking to find a way to identify strings with hyphens in JavaScript?

I am trying to extract specific parts of a URL that follow a certain pattern like the one below: http://example.com/somepath/this-is-composed-of-hypens-3144/someotherpath Specifically, I am interested in extracting the portion of the URL that consists of ...

Instructions for including a script and stylesheet exclusively on a single page of a website

I need to incorporate these two lines onto a single page of my website: <script src="//cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.js"></script> As well as <link href="//cdnjs.cloudflare.com/ajax/libs/OwlCa ...

Display or conceal the nearest element that was clicked

http://jsfiddle.net/KevinOrin/xycCx/1/ jQuery('.happening-main-text .readmore').click(function() { jQuery('.divmore').toggle('slow'); return false; }); ...

The dispatch function in redux-thunk is not functioning as expected

Having trouble with thunk and async dispatching? Check out this code snippet: function fetchProvider() { return (dispatch) => { graphqlService(fetchProviderQuery) .then((result) => { dispatch({ type: FETCH_PROVIDER, ...

Ways to access information from doc.data()

<template> <div> {{ id }} {{ title }} </div> </template> <script> import { useRoute } from 'vue-router' import 'firebase/firebase-firestore' import { db } from '@/fdb' export default ...