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

37 views
Skip to first unread message

codelearner

unread,
Mar 6, 2015, 5:25:14 AM3/6/15
to ang...@googlegroups.com

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.

Sander Elias

unread,
Mar 7, 2015, 7:48:45 AM3/7/15
to ang...@googlegroups.com
Hi Codelearner,

Hmm, this should normally work, can you build us a plunk that shows the issue?

Regards
Sander

Zishan J.

unread,
Mar 7, 2015, 8:51:04 AM3/7/15
to ang...@googlegroups.com
Thanks for the reply. I have figured out that it was due to track by $index, which always destroy the last row in list and then refreshes the list. I have changed $index to use another identifier and it works.

Regards,
Zishan J.


Disclaimer: The information transmitted in this message is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If you are not the intended recipient of this message you are hereby notified that any use, distribution, reproduction or any action taken in reliance upon this message is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/kCftEOuGATE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages