angular-ui/ui-sortable — pull request #48 by CyborgMaster (2013-11-12 18:15:57+00:00)
Title: Sortable messes up ng-repeat comments (ng1.2)

The `ng-repeat` directive uses comments to mark the beginning and end of repeat sections (at least in the latest version: `v1.2.0-rc3`). jQuery Sortable (and really all of jQuery for that matter) doesn't pay attention to comments and therefore clobbers them. Some clever work arounds are needed to get them to play together well.

For example, an `ng-repeat` generated section of the DOM might look as follows:
``` html

Group Start

Future Appointment

Group End

```

After dragging things around a couple of times, the DOM now looks like this:
``` html

Group Start

Future Appointment

Group End

```
Notice how all the `ngRepeat` comments have ended up at the bottom of the containing div. This causes `ng-repeat` to get very confused, throw javascript errors and crash when the model is modified. For example: If we now delete the "Group Start" filter, the following error is thrown:
```
TypeError: Cannot call method 'insertBefore' of null
```
and all of the filters are removed from the DOM (even though the model is still intact with only the "Group Start" filter removed).

Note: the above experiment was performed even with calling `element.sortable('cancel')` inside of every sort (which is why the filters ended in the same order), but jQuery.sortable still messed up the comments.

This can be seen either as a weakness of jQuery for not properly handling comment nodes as real nodes, or as a weakness of Angular's ng-repeat for depending on comment nodes for it's functionality (I personally don't think ng-repeat has any business using comment nodes), but either way, we need a work around.

I'm working on one now, will post it in a comment.