Removing the "delete" button upon clicking within ng-repeat

When displaying data using ng-repeat, there is a button to delete each item. Upon deleting an item, the delete button should only disappear for the specific item that was deleted.

<tr ng-repeat="paymentinfo in paymentList | filter:keyword | filter:money | filter:getdate | filter:{state: 'archived'}: archived.state ? true : false">
  <td id="outmouse">
    <ul style="list-style: none;" class="gt-reset">
      <li class="dropdown changecoursename">
        <a class="dropdown-toggle" data-toggle="dropdown">
          <span class="tableOperation norlmalstate">Open Course</span>
          <span class="tableOperation openedstate">more options</span>
          <b class="caret"></b>
        </a>
        <ul class="dropdown-menu">
          <li><a class="tableOperation" ng-click="paymentRemarks()">Remarks</a></li>
          <li><a class="tableOperation" ng-click="paymentReturn(paymentinfo)">Return</a></li>
          <li ng-switch on="paymentinfo.state">
            <div ng-switch-when="archived" class="archived__state">{{paymentinfo.state}}</div>
            <a ng-switch-default class="tableOperation" ng-click="paymentDelete();">{{deletebtn}}</a>
          </li>
        </ul>
      </li>
    </ul>
  </td>
</tr>

The location where deletion needs to occur:

<li ng-switch on="paymentinfo.state">
  <div ng-switch-when="archived" class="archived__state">{{paymentinfo.state}}</div>
  <a ng-switch-default class="tableOperation" ng-click="paymentDelete();">{{deletebtn}}</a>
</li>

My JavaScript code:

$scope.datas = [{
  date: '06-12-2016',
  name: 'Pinao Class',
  state: 'archived',
  remark: 'remarked',
  amount: 101,
  id: 21
}, {
  date: '15-04-2016',
  name: 'drivers Class',
  state: 'notarchived',
  remark: 'remarked',
  amount: 102,
  id: 22
}];
$scope.paymentList = $scope.datas;

$scope.deletebtn = "delete";

$scope.paymentDelete = function() {
  $scope.www = true;
  $scope.deletebtn = false;
}

Issue with my code: It deletes all elements instead of just the selected one.

Answer №1

Give this a shot

ng-click="deletePaymentInfo(this.paymentinfo);">// sending current object to delete function

$scope.deletePaymentInfo = function (paymentinfo ) {
      $scope.showLoader = true;
      var position = $scope.paymentRecords.indexOf(paymentinfo );
    if (position > -1) {
    $scope.paymentRecords.splice(position, 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

Tips for transferring the ID from one element to another using JavaScript

I'm attempting to create a slideshow using icons all within one class. The "active" style class will have an ID and represent the current picture. By clicking either the left or right button, I aim to change the style of the active class. const l ...

Refreshing a section of a webpage using AJAX and PHP

After creating a RESTful API in PHP, I can easily register information by accessing the address . This registration process involves sending a POST request. Below is an overview of my method: File: api.php <?php /* File: api.php */ private function ...

Tips for storing headers in NODE.JS?

Recently started learning NODE.JS Looking for some guidance. When I try to execute the command below: npm install --save express-handlebars I encounter the following error message: + <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cf ...

How to overcome rendering delay in angularjs with requirejs

My issue lies in the fact that "I am {{ 10 + 13 }}" briefly appears before the creation of the "store" module in main.js. <!DOCTYPE html> <html lang="en" ng-app="store"> <head> <title>...</title> <scrip ...

The Google Pie chart is displaying outside of the designated div area when placed inside a dropdown menu

Encountering an issue with my pie chart rendering outside of its parent div when placed within a dropdown menu. The chart successfully loads after the page is loaded, but only displays correctly if I hover over the dropdown and allow it to load. If I do ...

Executing Functions in AngularJS Controller using ng-submit on Form Submission

I'm currently working on a mobile app using AngularJS, Ionic framework, and Cordova. I have a specific scenario where I need to submit form data to the server and then navigate the user to a confirmation page once the server responds with a status of ...

Determining the correct type for a recursive function

I have created a function that is capable of recursively traversing through a nested or non-nested object to search for a specific key and extract its value. const findName = <T extends object>(obj: T, keyToFind: string): T[] => { return Object ...

Can local storage be accessed within a function and utilized during the Windows.onload event?

I have an onclick function that dynamically returns 'x' and stores it in a div. However, after a page refresh, the dynamic div resets and the data is lost. To prevent this, I stored the data in local storage within the 'test' function a ...

Breaking circular dependencies in JavaScript is a common challenge that developers face when

Having encountered a circular dependency issue between certain JS files, I am seeking steps to resolve it. Q1: Is repositioning the require function an appropriate solution? One suggested approach to resolve this issue is to move the require() statement ...

Bring in a sole getServerSideProps function to various pages in Nextjs

Is there a way to import the getServerSideProps method from this page to another and apply it across multiple pages? Here is the code snippet I am referring to: import DashboardLayout from "@app/layout/DashboardLayout"; import Overview from &quo ...

Design a recurring report using an endless JavaScript cycle

I am in the process of creating a brand new scheduled report and have encountered an issue. How can I incorporate a script that includes a loop to run a specific function every 10 seconds? Here's what I have so far: var count = 1; while(count > 0 ...

Tips for setting up a select dropdown in AngularJS using ng-options when the value is an object

How can I set the initial selection of a select field using ng-options? Consider the items we have: $scope.items = [{ id: 1, label: 'aLabel', subItem: { name: 'aSubItem' } }, { id: 2, label: 'bLabel', subItem: { ...

The dynamic concatenation of Tailwind classes is failing to have any effect, even though the full class name is being

I'm currently using Tailwind CSS within my Next.js project and I have a common method that dynamically returns the desired background color. However, despite adding the full class name, the background color is not displaying as expected. After reading ...

Showing a collection of articles on a webpage using Nuxt/content - Step by step guide

I have implemented the nuxt/content module to establish a documentation website. In a recent post on the Nuxt blog, they demonstrated displaying content in a separate index.vue page and post details on the _slug.vue page. My goal is to present a list of ...

Is there a way to utilize Javascript to retrieve elements without specifying an id?

I am faced with a challenge of accessing an element without an id but with a shared classname using Javascript. How can I accomplish this task successfully? My attempt to use the document.getElementsbyClassName property was unsuccessful due to the shared ...

Finding the date of a month prior based on a fixed initial date - here's how!

I have a specific requirement to display a subscription date range on a webpage in the following format: 31 May 2023 — 30 June 2023 When a user subscribes, the backend sends a fixed subscription start date that remains constant. For example, if a user ...

When representing audio as sound bars on a canvas, the previous drawing is retained if canvas height is not specified

After obtaining an audioBuffer containing an audio clip, I proceed to create a visualization by drawing a series of sound bars in the shape of a circle: const { audioContext, analyser } = this.getAudioContext(); const source = audioContext.createBufferSou ...

The javascript function in my file isn't being triggered by jquery

In my ASP.NET MVC project, I am facing an issue with a jQuery function in a JavaScript file located under the Scripts folder. This function is supposed to fill a textbox with the selected value upon clicking a dropdown, but for some reason it is not workin ...

Customize Bootstrap layout on the fly

I have encountered a slight dilemma. I am attempting to implement something similar to the following: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com ...

Tips for incorporating a live URL using Fetch

I'm having some trouble with this code. Taking out the &type = {t} makes it work fine, but adding it causes the fetch to not return any array. let n = 12 let c = 20 let t = 'multiple' let d = 'hard' fetch(`https://opentdb.com/ ...