Animation triggered when removing items from a filtered list using ng-repeat

I have a unique challenge where I need to display two different sections of an array in a single list by applying a filter within the ng-repeat. Instead of having two separate lists, I am filtering the array directly within the ng-repeat statement.

While removing items from the list, I want them to fade out smoothly using a fade-out animation, which is working as expected. However, when switching between the two views (changing the filter), I do not want the animation to be triggered, yet the ng-leave animation still occurs.

Q: How can I maintain the delete button animation while skipping the animation effect when toggling between the "visible" and "deleted" filters?

HTML:

<div ng-init="myFilter='visible'">Filter:
  <button ng-class="{'active':myFilter==='visible'}" ng-click="myFilter='visible'">Visible</button>
  <button ng-class="{'active':myFilter==='deleted'}" ng-click="myFilter='deleted'">Deleted</button>
</div>

<div ng-controller="myCtrl" >

  <div ng-repeat="item in (items | filter:{deleted: (myFilter==='deleted'?true:false) } )" class="repeat-item">
    {{item}} <div class="delete" ng-show="myFilter==='visible'" ng-click="remove($index)">delete</div> 
  </div>

</div>

CSS:

.repeat-item.ng-leave {
  -webkit-transition: 0.5s linear all;
  transition: 0.5s linear all;
}

.repeat-item.ng-leave.ng-leave-active {
  opacity: 0;
  height: 0px;
}

.repeat-item.ng-leave {
  opacity: 1;
  height: 30px;
}

Working plunkr: http://plnkr.co/edit/aeYCIu?p=preview

Answer №1

Hello, I recently shared a Plunker for you to check out.

Simply insert the following code:

class="default-style" ng-class="{'repeat-item': myFilter === 'visible'}">

Also, don't forget to include the CSS class:

.default-style{
  background: lightblue;
  margin-bottom: 5px;
  height: 40px;
}

This should resolve any issues you are experiencing.

Link to Plunker

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

Javascript variable scope

let preGameRequest = new XMLHttpRequest(); let preGameData; preGameRequest.open("GET", "/matches/live.json"); preGameRequest.onload = function() { preGameData = JSON.parse(preGameRequest.responseText); } preGameRequest.send(); console.log(preGameData) ...

Determine the exact location where the mouse was clicked on a webpage containing an iframe

I am trying to retrieve the mouse position on my HTML page, but I am encountering some issues. Here's what I have so far: document.onclick = function(click) { if (click.clientX<340){ myControl.inputs.selection = false; btnRotate.remove ...

Aligning the image at the center within a flex container

I am struggling with aligning an image and a link inside a div using the display: flex property. This is how my code looks: <div style="display: flex;"> <div class="site-title-container"> <img style="border-radius: 7px; width: 34px; h ...

The pop-up orientation is not being adjusted according to my CSS when it changes

I am currently working with Cordova 3.1.0 and Android 17. Here is the HTML code for my pop-up: <div id="rightNavPrpPopup1" data-role="popup" class="r-menu-dropdown"> <div class="r-menu-triangle"></div> <a class=" ...

Troubleshooting problem with Angular ngx-bootstrap datepicker positioning on mobile devices

Having an issue with ngx-bootstrap/datepicker, it works fine on larger screens but not on mobile screens. Any assistance would be appreciated. https://i.sstatic.net/ZGdyQ.png When the screen size is reduced to mobile (even on actual mobile devices), it o ...

Uninstalling Puppeteer from npm can be done by running a

Some time ago, I had integrated Puppeteer into an Express API on Heroku using their Git CLI. Recently, I decided to remove Puppeteer from the package.json file and went through the npm install process before trying to push to GitHub. However, it appears th ...

Altering pointer during drag操作

Is it feasible to customize the cursor during a drag operation? I've been exploring ways to achieve this for some time now. My goal is to replace the default 'not-allowed' cursor that appears when dragging an object with a different cursor. ...

Visibility of Code in AngularJS

After inspecting the source code of a website built with Angular today, I came across a snippet that made me ponder whether it's advisable to have such elements visible to everyone. ul class="nav-account desktop-only" ng-show="!User.isAuthenticated" ...

Struggling with rendering components in REACT?

I'm encountering an issue with rendering the Butcher Shop component. I can't seem to pinpoint what's causing it to be null or undefined. Can someone help me identify the mistake? Nothing is showing up on the DOM and I keep getting this error ...

Angular 2: Enhancing Tables

I am looking to create a custom table using Angular 2. Here is the desired layout of the table: https://i.sstatic.net/6Mrtf.png I have a Component that provides me with data export class ResultsComponent implements OnInit { public items: any; ngO ...

Exporting the output of an AngularJS directive, specifically an ng-repeat, into an individual downloadable HTML file - a comprehensive guide

Can Angular be used to download the content of a div (specifically with ng-repeat directive) in a new HTML file? I attempted to do this: var content = 'file content'; var blob = new Blob([ content ], { type : 'text/html' }); $scope.ur ...

Is it possible to conceal or disregard text elements from the web browser search function by using CTRL+F?

I have a complex web application interface with a dedicated area for content display. Is there a way to ensure that when users utilize the browser's text search function (CTRL+F), the UI elements are ignored and only the actual content is searched? ...

Comparing the start and end times in tabular or array input using Yii2

Can I compare the start and end times in the Yii2 client/ajax validation for my form? https://i.sstatic.net/bC48T.png This is how my view file code looks: <?php foreach ($model->weekDaysList as $index => $value) : ?> <div class="row"& ...

Retrieving properties from a selector's output function

My situation is similar to the scenario described in the accessing react props in selectors documentation. However, in my case, let's assume that the visibilityFilter is coming from the props. Is there a way to achieve something like the following? e ...

Tips for replicating input fields that fetch information via ajax requests

My current code fetches data using AJAX from the database and allows for adding an unlimited number of text fields: <div class="input" id="itemRows"> <div class="clone"> <style> .txtHint { width:95 ...

Alert Box Displays Variable Name Instead of Label Name in Form Validation - MM_validateForm()

Looking at the screenshot, you can see variable names such as "email_address", "email_message" and "email_subject". I would like these to be displayed as "Email", "Message" and "Subject" instead. The validation in this form is done using MM_validateForm() ...

What is the most expedient method to refresh blog content upon detecting a change?

I am interested in developing a blog that is extremely user-friendly and would like to find the most effective method for displaying recent blog posts. One approach could involve programmatically refreshing a div every 5 seconds or sending a request every ...

What is the best way to obtain the final HTML output once all scripts have been executed

Is there a way to obtain the final HTML after all scripts have been executed? The scripts on the page are adding and changing controls and CSS, and I want to see the HTML of the display as a static page. Is there a method to achieve this? Edit: For exa ...

Is there a way to transfer table row data to another table by simply clicking on the corresponding checkbox in the same row?

I'm working with a table that includes 4 fields: service, amount, tax, and action. My challenge is to have the data from any row in the first table added to a second table when its checkbox is selected. The second table should have the same fields a ...

Bootstrap Modal fails to display unless fade class is included

I'm feeling lost with this situation. I am working with bootstrap 4 and trying to create a modal without any animation effects. According to the official website, it says to remove the "fade" class for a non-animated modal. So I followed the instructi ...