Ways to prevent an element from activating ngAnimate

Building a content slider for my project with limited experience in AngularJS. Came across this plunker that fits perfectly. Check out the live version of my page here. It's in Russian, but you'll find the slider in the center - a section with 8 cards.

The issue: Slider is controlled by arrows below it, but clicking the red button inside a card updates the model and applies ng-enter and ng-leave classes to the parent container, triggering slider animation. How can I prevent these red buttons from applying these classes?

UPDATE: See this plunker illustrating the problem. The animation should be triggered by clicking on Prev and Next buttons, but it also happens when clicking "Choose" or "Chosen" links, which update the model.

This is the markup:

<body ng-controller="MainCtrl">
    <div class="page-container">
      <div class="gift-page" ng-class="direction" ng-repeat="page in gifts | partition: 6 | offset: currentPage | limitTo: 1">
          <ul class="gift-list clearfix">
              <li class="gift" ng-repeat="gift in page">
                  <div class="gift-item">
                      <div class="gift-details">
                          <h3>{{gift.title}}</h3>
                          <span class="points">{{gift.points}} points</span>
                          <a href="" class="buy" ng-show="!gift.ordered" ng-click="addToBasket(gift)">Choose</a>
                          <a href="" class="bought" ng-show="gift.ordered" ng-click="removeFromBasket(gift)">Chosen</a>
                      </div>
                  </div>
              </li>
          </ul>
      </div>

    </div>
    <div class="controls">
      <button ng-click="prev()">Prev</button>
      <button ng-click="next()">Next</button>
    </div>
  </body>

Answer №1

A fast solution, although not the most optimal, is to disable animation before taking action and then re-enable it afterwards:

  $scope.addToBasket = function(gift){

    $animate.enabled(false);

    gift.ordered = true;

    $timeout(function(){
      $animate.enabled(true);
    })
  }

Check out the demo on Plunker. I will continue to search for a better solution later))

Answer №2

To prevent the ng-click event from bubbling up, you can include $event.stopPropagation(); in your code like this:

<a href="" class="purchase" ng-show="!item.purchased" ng-click="addToCart(item); $event.stopPropagation();">Add to Cart</a>

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

Request to access embedded server with CORS (unchangeable) restrictions

When working with HTML4, I didn't encounter any issues creating an XmlHttpRequest to fetch an AJAX packet. However, as I'm moving on to HTML5, I've come across the term cors (which is new to me). Given that the server I'm dealing with i ...

After a short period of time, the Next.js server will shut down on its own when executing the command "npm run dev."

I am trying out Next.js for the first time and followed the installation instructions from the official page. npx create-next-app@latest hello-word However, after installing and running "npm run dev" or "yarn dev", the server starts on port 3000 but then ...

Encountering a problem when trying to import images from the assets folder due to

When working with Vite-react-app and importing images from the assets folder, I encountered errors in the terminal related to webpack. Here are some of the errors: https://i.sstatic.net/QWW2b.png https://i.sstatic.net/PSj6Y.png https://i.sstatic.net/in4 ...

Embedding WebGL into XML files

My goal is to manipulate my XML documents directly and display specific data/elements using WebGL. To accomplish this, I incorporate xhtml:script to execute my JavaScript code. Although the WebGL API is present (such as window.WebGLRenderingContext), I en ...

collecting user input in React.js

After doing some research on React.js from this website, I stumbled upon a piece of code that left me puzzled. As far as I can tell, the checkbox for isGoing will be pre-filled as true (checked) and the numberOfGuests will be set to 2. However, I found m ...

Adding a basic fade-in effect to an element that is lazily loaded using JavaScript

Is there a way to enhance my lazy loading script with an animation effect, such as 'show(slow)', so that each post fades in as it loads? This is my current JavaScript: jQuery(function(){ var page = 2; var myurl = blogUrll var lo ...

What is the process for including a scope in an Angular.js HTTP controller?

I am looking to access a $scope variable within this controller in order to utilize Angular functions like ng-click and ng-change in my HTML. Currently, I am only able to use the $http function but unable to execute any Angular methods on it. I am struggli ...

Issues with PHP ajax causing database insertion failure

Here is the code for making an AJAX request: AJAX var date = new Date().toLocaleTimeString(); var text=this.value; var id=1; $.ajax({ type: "GET", url: "StoreMessages.php" , data: { room: id, msg:text, sendat:date } }); PHP Code if(isset($_GET['r ...

How come my image isn't moving from my folders to my stylesheet for a DIV element?

My goal is to replicate a webpage template as a way to improve my understanding of HTML/CSS. I am attempting to use an image as the background for a DIV in my document, but for some reason, it's not appearing. Please keep in mind that I am still new t ...

Angular, JavaScript, and PHP are three powerful programming languages that

This file contains HTML code <ul class="list"> <li id="numword" data-score="{{item.score}}" class="" ng-repeat="item in words track by $index"> {{item.word}} {{item.score}} </li> </ul> Here is the visual representa ...

Increase the height of a component when viewed on mobile devices

https://jsfiddle.net/7v0dyfo3/ This is the concept I am attempting to implement for a listing, albeit without proper styling. While it looks good on most screens, the issue arises with its resizing behavior. I aim for the episode-box div to adapt its heig ...

Encountering infinite loop in Node modules triggering a Catch-22 situation while attempting to use M

I have been working on a project that involves using some customized Node.js modules. I have developed a 'helpers' module that helps with loading various helper methods: /helpers/index.js: var mutability = require('./mutability'), ...

Completion of operations is signaled by the calling of the async callback function in Node

I'm having trouble with using the async library to handle asynchronous functions and achieve the desired functionality. My goal is to construct a JSON object through multiple calls to a redis database. I want to ensure that the JSON object is only re ...

"Incorporating error messages into the Angular callback API for when it fails

Currently engaged in developing an Angular application that interacts with the flickr API. To effectively use the response from flickr, it is necessary to define a jsonFlickrFeed callback function. Check out this link for detailed instructions. The functi ...

Modifying column array properties using jsstore

I am working with a jsstore table called tblInvoice const tblInvoice: ITable = { name: "invoice", columns: { // Here "Id" is name of column id: { autoIncrement: true, primaryKey: true, notNull: false }, branchId: { ...

Retrieving file name using Fetch call in React

While working on a React project, I am using the fetch method to retrieve a file in .pdf format which is also named. Now, my goal is to extract that filename. function downloadPdf() { fetch(BASE_URL + `/example/example/pdf/${exampleId}`) .then(r ...

Issues with Javascript functionality on aspdotnetstorefront site

Lately, I've been facing some challenges with my Javascript and jQuery codes when trying to implement them in the storefront. Despite attempting different methods to create a slider, none seem to work within the store environment - even though they fu ...

Browser Bing Parser

After successfully creating a web parser for Google search results, I decided to implement a similar parser for Bing. However, I encountered an error that I couldn't resolve. Below is the code snippet that caused the issue: var rows = htmlDoc.Documen ...

Node.js Implementing css styles

Here are my folders: server.js index.html -public --css --ses.scss --style.css This is the Server js code: var express = require('express'); var path = require('path'); var publicPath = path.resolve(path.join(__dirname, ...

The inline-table display is not functioning properly when the content width is limited

The challenge I'm facing involves designing CSS for a web application centered around photo uploads displayed as polaroids. Each photo is encased in white padding, with extra padding at the bottom and the design adapts responsively. If a user adds a ...