diff --git a/js/angular/directive/list.js b/js/angular/directive/list.js index c5577151c2..a892ae5367 100644 --- a/js/angular/directive/list.js +++ b/js/angular/directive/list.js @@ -250,7 +250,12 @@ function($animate, $timeout) { onReorder: function(el, oldIndex, newIndex) { var itemScope = jqLite(el).scope(); if (itemScope && itemScope.$onReorder) { - itemScope.$onReorder(oldIndex, newIndex); + //Make sure onReorder is called in apply cycle, + //but also make sure it has no conflicts by doing + //$evalAsync + itemScope.$evalAsync(function() { + itemScope.$onReorder(oldIndex, newIndex); + }); } }, canSwipe: function() { diff --git a/test/html/has-anything-dynamic.html b/test/html/has-anything-dynamic.html index 2b3945782b..d79fd01bd8 100644 --- a/test/html/has-anything-dynamic.html +++ b/test/html/has-anything-dynamic.html @@ -9,19 +9,18 @@ -
- -

Header Bar

-
+ +

Header Bar

+
-
- -

Footer bar

-
-
+ +

Footer bar

+
diff --git a/test/unit/angular/directive/list.unit.js b/test/unit/angular/directive/list.unit.js index 5121504c93..83191f10c0 100644 --- a/test/unit/angular/directive/list.unit.js +++ b/test/unit/angular/directive/list.unit.js @@ -110,6 +110,8 @@ describe('ionList directive', function() { el.scope().$onReorder = jasmine.createSpy('$onReorder'); options.onReorder(el, 2, 3); + expect(el.scope().$onReorder).not.toHaveBeenCalled(); + el.scope().$apply(); expect(el.scope().$onReorder).toHaveBeenCalledWith(2,3); });