Skip to content

Commit cc46735

Browse files
committed
fix(ionReorderButton): fix onReorder not triggering angular digest
1 parent 4d793fd commit cc46735

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

Diff for: js/angular/directive/list.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ function($animate, $timeout) {
250250
onReorder: function(el, oldIndex, newIndex) {
251251
var itemScope = jqLite(el).scope();
252252
if (itemScope && itemScope.$onReorder) {
253-
itemScope.$onReorder(oldIndex, newIndex);
253+
//Make sure onReorder is called in apply cycle,
254+
//but also make sure it has no conflicts by doing
255+
//$evalAsync
256+
itemScope.$evalAsync(function() {
257+
itemScope.$onReorder(oldIndex, newIndex);
258+
});
254259
}
255260
},
256261
canSwipe: function() {

Diff for: test/html/has-anything-dynamic.html

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@
99

1010
<ion-tab title="So Tabular!">
1111

12-
<div ng-if="$root.headerExists">
13-
<ion-header-bar class="bar-positive"
14-
ng-class="{'bar-subheader': $root.isSubheader}">
15-
<h1 class="title">Header Bar</h1>
16-
</ion-header-bar>
12+
<ion-header-bar ng-show="$root.headerExists"
13+
class="bar-positive"
14+
ng-class="{'bar-subheader': $root.isSubheader}">
15+
<h1 class="title">Header Bar</h1>
16+
</ion-header-bar>
1717
</div>
1818

19-
<div ng-if="$root.footerExists">
20-
<ion-footer-bar class="bar-assertive"
21-
ng-class="{'bar-subfooter': $root.isSubfooter}">
22-
<h1 class="title">Footer bar</h1>
23-
</ion-footer-bar>
24-
</div>
19+
<ion-footer-bar ng-show="$root.footerExists"
20+
class="bar-assertive"
21+
ng-class="{'bar-subfooter': $root.isSubfooter}">
22+
<h1 class="title">Footer bar</h1>
23+
</ion-footer-bar>
2524

2625
<ion-content>
2726
<div class="card">

Diff for: test/unit/angular/directive/list.unit.js

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ describe('ionList directive', function() {
110110

111111
el.scope().$onReorder = jasmine.createSpy('$onReorder');
112112
options.onReorder(el, 2, 3);
113+
expect(el.scope().$onReorder).not.toHaveBeenCalled();
114+
el.scope().$apply();
113115
expect(el.scope().$onReorder).toHaveBeenCalledWith(2,3);
114116
});
115117

0 commit comments

Comments
 (0)