animate rest ng-repeat element when a child is removed - angularjs

I am removing an element in ng-repeat using javascript splice method ..elements of my ng-repeat are in two rows not in list styles ...now i need to apply a animation on the rest of element(not on the element being removed. when rest of element re adjust them..according to their position ...mainly i need to show the animation when they move from one place to another .

Related

ReactJS animating removal/addition from array of components at the same time

I have several list components in a tree-like data structure and I want to animate them in a way that when I click on an item, its children slide in from the right and at the same time the previous list slides out to the left.
I used an array for this with react-transition-group, if I add items to it, it works, but if I try to remove one from it, it fails.
I have a demo here:
https://codesandbox.io/s/k1wyqo64lo
If I uncomment line 91 path.shift() it stops animating.
How can I make them animate at the same time?

How to preserve DOM elements when using ng-repeat with filter?

I have an ng-repeat with a filter. When some items are filtered out by the filter and then they are restored after another filter change there are new DOM elements created for these items. If there was any DOM manipulation on the item it gets lost after item is hidden and restored with filter.
Is there a way to keep the DOM elements, even when item is removed by filter?
I tried using track by, but it doesn't help.
Here is a fiddle that recreates the problem.
Steps to recreate:
Click the button to apply colors to DOM elements
Type something in the filter input (for example 'ap') to hide some of the elements
Remove the filter. The restored elements lost their style.
Angualr is dynamically adding and removing those templates. By template I mean whatever tag(s) are inside your ng-repeat. There is no way to preserve that in an ng-repeat. Instead, if you want this color change to be preserved, it needs to be a part of the model you are ng-repeat ing over. Does that make sense?
Add the color directly to the template style="color: {{fruit.color}}"
See this for what I am talking about
http://jsfiddle.net/nferjvsp/1/

Animating ng-repeat index changes using custom directive

This forked Plunker shows two ng-repeats each displaying an array as a list. Each list item uses a custom directive to animate whenever an up or down arrow is clicked.
The first list, which records changes to array item values animates correctly but the second, which records changes to array item indexes does not.
Can anybody suggest how to edit the directive to animate the second list correctly?
The way you move the elements triggers incorrect animation. Try to do it like this
function arrayMove(arrayVar, from, to) {
var item = arrayVar.splice(from, 1).pop();
arrayVar.splice(to, 0, angular.copy(item));
}
You need to make a (deep) copy of the element to preserve some properties like $$hashkey used by AngularJS to track the objects.

ng-repeat doesn't trigger $destroy on specific element

I have created a directive and using inside ng-repeat. I am using remove button also to remove specific element from the list. The issue is, whenever I remove specific element from list, it always trigger $destroy in my directive on the last element in the list instead of specific element.
For example, I have 4 elements in the list like [1,2,3,4]. My directive displays 2 text boxes. I uses ng-repeat to iterate over list and display directive with 2 textboxes and remove button in every row. Now I clicked the remove button on 2nd row, but it triggers the $destroy on 4th element in my directive instead of 2nd.
Any idea how to fix this, to trigger the $destroy on specific element only.
It's due to track by $index, in which case it will always remove the last row in the list.

Animating list items when moved within array

Plunker
This plunker shows an array displayed as a list using ng-repeat
Each array item has an up and down button allowing it to to change position with the array item above or below.
I'm also using angular-animateto flash each item red when it's position is changed.
But what I'd like to do is flash red the item moving up and and flash blue the item moving down.
Any suggestions welcome
I'm not an expert at angularJS, but, I do have an idea:
http://jptacek.com/2015/03/angularJS-CSS-Animation/
There are five AngularJS events
enter - DOM element is add to the DOM tree
leave - DOM element is removed from the DOM tree
move - DOM element is moved within the DOM tree
addClass - A class is added to an element
removeClass - A class is removed from an element
So, although "move" is only working on the button you are clicking, you can change your javascript to add a class to the other elements that you swap with and move.
Then you can trigger the CSS animation by using something in your css following the
[class]-[event]-[state]
model, where it can be like
.ng-addClass { ... }
.ng-addClass-active { ... }

Resources