Skip to content

Commit

Permalink
fix(ionReorderButton): fix onReorder not triggering angular digest
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed May 20, 2014
1 parent 4d793fd commit cc46735
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
7 changes: 6 additions & 1 deletion js/angular/directive/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 10 additions & 11 deletions test/html/has-anything-dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@

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

<div ng-if="$root.headerExists">
<ion-header-bar class="bar-positive"
ng-class="{'bar-subheader': $root.isSubheader}">
<h1 class="title">Header Bar</h1>
</ion-header-bar>
<ion-header-bar ng-show="$root.headerExists"
class="bar-positive"
ng-class="{'bar-subheader': $root.isSubheader}">
<h1 class="title">Header Bar</h1>
</ion-header-bar>
</div>

<div ng-if="$root.footerExists">
<ion-footer-bar class="bar-assertive"
ng-class="{'bar-subfooter': $root.isSubfooter}">
<h1 class="title">Footer bar</h1>
</ion-footer-bar>
</div>
<ion-footer-bar ng-show="$root.footerExists"
class="bar-assertive"
ng-class="{'bar-subfooter': $root.isSubfooter}">
<h1 class="title">Footer bar</h1>
</ion-footer-bar>

<ion-content>
<div class="card">
Expand Down
2 changes: 2 additions & 0 deletions test/unit/angular/directive/list.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit cc46735

Please sign in to comment.