Toggle button visibility on ng-repeat item click

Hello everyone, I'm encountering an issue with displaying and hiding buttons in ng-repeat.

<div class="row" ng-repeat="item in items">
   <button type="button" ng-click="add()">+</button>
   <button type="button" ng-click="remove()">-</button>
</div>

It's looping items times, I only want the add button to be visible initially, and on click I want to hide the add button and show the remove button, but only for that specific iteration. I don't want this interaction to affect other iterations. When the remove button is clicked, I want it to hide and show the add button again.

I have considered implementing this functionality either within the controller or inline.

Thank you in advance!

Answer â„–1

It is important to include a property like "added" or "remove" in your code so that you can easily determine if something has been added or removed.

<div class="row" ng-repeat="a in b">
   <button type="button" ng-if="!a.added" ng-click="add(a)">+</button>
   <button type="button" ng-if="a.added" ng-click="remove()">-</button>
</div>

In the click method, make sure to add the following:

function add(x) {
 ... insert your code here
 x.added = true
}

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

Mysterious Loop in JavaScript Unfolding with Three.Js

In order to expand my knowledge of Angular and Three.Js, I am currently working on a prototype SPA that showcases different 3D elements rotating. There are several Angular templates accessible through a navigation menu, each displaying unique rotating elem ...

Using Javascript to test a specific item in an asp Listbox

Let's consider a scenario where there is ListBox1 containing the following listitem: <asp:ListItem Value="No.1">No.1</asp:listitem> In addition, we have a label for a test purpose: <asp:Label ID="lblLabel" runat="server" Text="Label ...

State change shows the previous and current values simultaneously

I've been working on updating the values of initUsers on the DOM. The initial state values work fine, but when I try to update initUsers, it displays different values than expected. Essentially, entriesNum receives a number as an event and changes th ...

The function call FirstName.Val() is invalid and will not execute as intended

When attempting to create an array called requestData using the input values from a user details form, I encountered an error stating that .val() is not a function. The code snippet where this problem occurred is as follows: Jquery $('#submit' ...

Merging two arrays concurrently in Angular 7

When attempting to merge two arrays side by side, I followed the procedure below but encountered the following error: Cannot set Property "account" of undefined. This is the code in question: acs = [ { "account": "Cash In Hand", ...

Is there a way for me to move the dot icon along the dotline?

Here is the code snippet: jsFiddle I have successfully implemented a click event to change the style of selected dots in dotline. Now, my query is : How can I enable dragging functionality for the dot icon within dotline? Your assistance on this matte ...

Customize your AppBar with Material UI and NProgress integration

Snippet of Code: <AppBar color='inherit' position='fixed'><AppBar> I'm currently working with material-ui and facing an issue where nprogress doesn't show up at the top in my Nextjs App when using it in conjunctio ...

Switch up the CSS variable within an embedded iframe

I'm in a predicament with a specific issue. I am currently utilizing Angular to incorporate an Iframe. Let's imagine the angular app as A and the Iframe as B. B is being loaded within A. Within B, I have utilized CSS variables to define colors. I ...

Tips for designating all content within a <div> element to open in a blank target (target="_blank")

I am looking to open all content within a specific <div> in a new tab (target="_blank"). I am open to any solution, whether it involves JS, CSS, HTML, classes, IDs, etc. I experimented with using <base target="_blank">, but it affect ...

Utilize jQuery to dynamically assign classes to list items within a unordered list based on the length of an array

HTML: <ul class="tickboxes"> <li><i class="fa fa-check"></i></li> <li><i class="fa fa-check"></i></li> <li><i class="fa fa-check"></i>< ...

Exploring Amcharts using detailed JSON data

[{"SUM_PTS":{"datatype":"INTEGER","length":"8","value":"29903727","obfuscated":"false"},"SUM_TOTAL":{"datatype":"INTEGER","length":"10","value":"1644704985","obfuscated":"false"},"MID":{"datatype":"ALPHANUMERIC","length":"27","value":"Vendor 1","obfuscated ...

Guide on utilizing linux curl for authentication and accessing data post login

I am in possession of a Stiebel Eltron heat pump device for my home and I am seeking to utilize Linux shell curl (not php) to login via POST request and retrieve data through a GET request once logged in Here is the structure of my curl login POST call (I ...

Techniques for transferring PHP print_r arrays to Javascript

Array ( [0] => Array ( [sno] => 1 [name] => Sivamani [contact] => 750241378 [$city] => Madurai ) ) Array ( [1] => Array ( [sno] => 2 ...

After refreshing, the base href in the environment is characterized as undefined

Within my angularjs application, I have configured the env.js file as shown below: (function (window) { window.__env = window.__env || {}; // API url window.__env.apiUrl = 'http://aaaaaaa.com/'; // Base url window.__env.baseUrl = '/angula ...

Encountering a syntax error while attempting to send Node.js data to MySQL database

I am facing a problem with an SQL error that I just can't seem to figure out. Here is the error message: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual for MySQL server version for correct syntax near 'x Disney â ...

Add a dynamic widget to a specific element in the document object model in real time

Is there a way to dynamically create a jQuery UI widget using a string? You can easily do this by following the example below: $(function() { $("selector").widget() }) However, what I am trying to accomplish is slightly different. Here is an examp ...

TypeScript enabled npm package

I am currently developing a npm module using TypeScript. Within my library, I have the following directory structure: . ├── README.md ├── dist │ ├── index.d.ts │ └── index.js ├── lib │ └── index.ts ├── ...

The format of the date cannot be modified when using DesktopDatePicker as a React Component

I've been attempting to modify the appearance of the component, but the UI keeps showing the date in month-year format. <DesktopDatePicker inputVariant="outlined" label="Pick-up date" id="date ...

When working with Function components in NextJS, it's important to note that they cannot be assigned refs directly. If you're trying to access a ref within a Function component, you

I'm having an issue with wrapping a card component using the Link component from 'next/link'. Instead of redirecting me to the desired link when I click the card, I receive a warning that says 'Function components cannot be given refs. ...

Using JQuery, it is possible to search for elements by one specific class while excluding others

Looking for a way to target elements with a specific class, but only if they don't have another class attached to them. Here is an example: <li class="target-class exclude-class"></li> <li class="target-class exclude-class"></li& ...