@@ -44,6 +44,8 @@ angular.module('ui.sortable', [])
4444 scope . $watch ( attrs . ngModel + '.length' , function ( ) {
4545 // Timeout to let ng-repeat modify the DOM
4646 $timeout ( function ( ) {
47+ // ensure that the jquery-ui-sortable widget instance
48+ // is still bound to the directive's element
4749 if ( ! ! element . data ( 'ui-sortable' ) ) {
4850 element . sortable ( 'refresh' ) ;
4951 }
@@ -176,18 +178,23 @@ angular.module('ui.sortable', [])
176178 } ;
177179
178180 scope . $watch ( attrs . uiSortable , function ( newVal /*, oldVal*/ ) {
179- angular . forEach ( newVal , function ( value , key ) {
180- if ( callbacks [ key ] ) {
181- if ( key === 'stop' ) {
182- // call apply after stop
183- value = combineCallbacks (
184- value , function ( ) { scope . $apply ( ) ; } ) ;
181+ // ensure that the jquery-ui-sortable widget instance
182+ // is still bound to the directive's element
183+ if ( ! ! element . data ( 'ui-sortable' ) ) {
184+ angular . forEach ( newVal , function ( value , key ) {
185+ if ( callbacks [ key ] ) {
186+ if ( key === 'stop' ) {
187+ // call apply after stop
188+ value = combineCallbacks (
189+ value , function ( ) { scope . $apply ( ) ; } ) ;
190+ }
191+ // wrap the callback
192+ value = combineCallbacks ( callbacks [ key ] , value ) ;
185193 }
186- // wrap the callback
187- value = combineCallbacks ( callbacks [ key ] , value ) ;
188- }
189- element . sortable ( 'option' , key , value ) ;
190- } ) ;
194+
195+ element . sortable ( 'option' , key , value ) ;
196+ } ) ;
197+ }
191198 } , true ) ;
192199
193200 angular . forEach ( callbacks , function ( value , key ) {
0 commit comments