Unable to remove the necessary row with Angular.js/JavaScript

I am facing an issue in deleting the correct row from an array using Angular.js. Below is the code snippet that I am working with:

<tr ng-repeat="d in days">
        <td>{{d.day_name}}</td>
        <td>
          <table>
            ... (Code continues)
          </table>
        </td>
     ... (More code here)
      </tr>
    </tbody>
          </table>
        </td>
      </tr>

The current output of the above table is displayed in the image below:

https://i.stack.imgur.com/xxlue.png

In this table, when I click on the middle row's - button, it should delete only that specific row. However, the deletion process is incorrect as shown in the screenshot below:

https://i.stack.imgur.com/qIxX4.png

Even though I deleted the second row from the first screenshot, the subcategory part of the third row was mistakenly removed. This issue arises in my controller-side code as well:

$scope.days=[];
    $http({
        method:'GET',
        url:"php/customerInfo.php?action=day",
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).then(function successCallback(response){
        //console.log('day',response.data);
    angular.forEach(response.data, function(obj) {
      obj.answers = [];
      $scope.addNewRow(obj.answers);
      $scope.days.push(obj);
    });
    },function errorCallback(response) {
    })
    }
    
   $scope.addNewRow = function(answers,hasDelete) {
    answers.push({
      category: null,
      subcategory: null,
      comment: null,
      hasDelete: hasDelete ? hasDelete : false
    });
  };
  
  $scope.removeRow = function(answers, $index){
    answers.splice($index, 1);
    //answers.splice(answers.length-1,1);
  };

All the data is dynamically bound, and I need to ensure that the correct row is deleted.

Answer №1

Attempt to eliminate the $ sign from the $index parameter.

$scope.deleteItem = function(answers, index){
answers.splice(index, 1);
//answers.splice(answers.length-1,1);

}

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

Electron triggers MouseLeave event on child elements

Dealing with mouse hover events can be a bit tricky, especially when working with AngularJS in an Electron-hosted app. Here's the HTML template and script I'm using: HTML: <div id="controlArea" (mouseenter) = "onControlAreaEnter()" ...

Using JavaScript to post data to a PHP script, then triggering the execution of another

My website has two distinct pages with different purposes. On one page, there is a button that, when clicked, sends data to finalizecontract.php. The other page, contract.php, creates a TCPDF form populated with the database information and saves the resu ...

The perpetual loop in React context triggered by a setState function within a useEffect block

I'm experiencing an endless loop issue with this context component once I uncomment a specific line. Even after completely isolating the component, the problem persists. This peculiar behavior only manifests when the row is discounted and the browser ...

Completing a fetch promise and sending the outcome to a function that is not awaited

I have a function that retrieves data from a Postgresql database and returns it. The expected behavior is to fetch the data using the async function getCat(), process it in const Catalogue, and then return it to a ReactJS component. catalogue.tsx: import ...

Testing Angular's $log functionality using Jasmine unit tests

I've encountered some difficulties while unit testing $log. I wanted to attempt a simple test that takes the injected value and tests it, without connecting to a restful call yet. I'm using angular mocks and have defined the module through it. S ...

Capture an image of the element

Hi there, I'm currently attempting to use PhantomJS to capture a screenshot of a specific element. I'm utilizing the PhantomJS bridge for Node.js: phantom Here's what I have so far: page.includeJs('http://ajax.googleapis.com/ajax/libs ...

Utilizing destructuring and Object.entries for advanced formatting

I'm embarking on a new React project and facing an issue with the JSON data structure returned by my API for meetings. I attempted to utilize destructuring and Object.entries. This is what I currently have: { "meetings": [ ...

JavaScript Functions Not Being Executed by Onclick Event in Internet Explorer 8

When a user clicks, I need two functions to run. This works in Firefox and Chrome, but not in IE8. The first function should display a modal (indicating that the form is being saved, although it's not showing up) while the second function saves the f ...

Guide on sending data to MongoDB using Postman

I am currently facing an issue while trying to send data to the MongoDB database using Postman. Despite everything seeming fine, I keep encountering errors. https://i.stack.imgur.com/Gcf5Q.jpg https://i.stack.imgur.com/ntjwu.jpg https://i.stack.imgur.co ...

Dynamically showcasing content in an HTML table

Having trouble with this code snippet. It's supposed to iterate through array objects and display them in an HTML table. The third row should have buttons, but nothing is showing up. Can you spot the issue? Here's the HTML code: <html> & ...

Navigating Angular.js: finding my way to the endpoint paths

Despite my best efforts and extensive research, I find myself in need of assistance! I have a web application that utilizes node and express on the server side, with Angular on the client side. My issue lies with angular routing. IMPORTANT DETAILS My cur ...

"Implementing a Texture as Material in Three.js: Step-by-Step Guide

I recently discovered Three.js and I'm really enjoying it. As a newcomer to JavaScript, I'm eager to delve deeper into animation and related topics. //UPDATE I've been working on this code snippet, but unfortunately, it's not functioni ...

Protractor tests succeeding prior to complete page load

Recently, my protractor tests have been failing after updating the node_modules. Strangely, it seems like the tests are initiating before the page is fully loaded: Connecting to the selenium server at http://127.0.0.1:4444/wd/hub [launcher] Running 1 inst ...

Deactivate any days occurring prior to or following the specified dates

I need assistance restricting the user to choose dates within a specific range using react day picker. Dates outside this range should be disabled to prevent selection. Below is my DateRange component that receives date values as strings like 2022-07-15 th ...

What are the steps to create a shadow effect on a bar chart in ChartJs?

Currently, I am utilizing version 3.9 of chartjs to construct a bar chart. My goal is to incorporate a shadow effect on the bars resembling the image in this link: Despite my efforts, I have not been able to locate instructions on how to achieve this in t ...

What is the best way to switch a Boolean value in React Native?

Struggling with toggling a Boolean state from true to false when the result is undefined. Tried several methods but none seem to work. The boolean state in the constructor is defined like this: class UserInfo extends Component{ constructor(props){ s ...

Navigating through different components in React is made possible with React Router

I have views in my application that depend on each other. For example, in one view a user can choose an item from a list (generated on the server), and in the next view they can perform operations on that selected item. The item is passed to the second v ...

Asynchronous operations and recursive functions in the world of Node.js

When working with express and mongoose, I frequently find myself needing to perform batch operations on collections. However, the typical approach involves callbacks in nodejs concurrency coding, which can be cumbersome. // given a collection C var i = 0 ...

Transferring data from a JavaScript struct array to GLSL

Struggling to configure the values of a structure containing all the lights in my WebGL app using JavaScript. The layout of the structure is as follows: struct Light { vec4 position; vec4 ambient; vec4 diffuse; vec4 specular; vec3 spo ...

When individuals discuss constructing a stack, or a full stack, in JavaScript, what exactly are they referring to and how does this concept connect with Node JS?

I recently started learning about node.js, but I'm struggling to understand its purpose. I have experience with JavaScript/jQuery and Angular, so I don't see how Node can benefit me. People keep talking about full stack JavaScript but I'm st ...