@@ -42,6 +42,8 @@ angular.module('ui.sortable', [])
4242 scope . $watch ( attrs . ngModel + '.length' , function ( ) {
4343 // Timeout to let ng-repeat modify the DOM
4444 $timeout ( function ( ) {
45+ // ensure that the jquery-ui-sortable widget instance
46+ // is still bound to the directive's element
4547 if ( ! ! element . data ( 'ui-sortable' ) ) {
4648 element . sortable ( 'refresh' ) ;
4749 }
@@ -174,18 +176,23 @@ angular.module('ui.sortable', [])
174176 } ;
175177
176178 scope . $watch ( attrs . uiSortable , function ( newVal /*, oldVal*/ ) {
177- angular . forEach ( newVal , function ( value , key ) {
178- if ( callbacks [ key ] ) {
179- if ( key === 'stop' ) {
180- // call apply after stop
181- value = combineCallbacks (
182- value , function ( ) { scope . $apply ( ) ; } ) ;
179+ // ensure that the jquery-ui-sortable widget instance
180+ // is still bound to the directive's element
181+ if ( ! ! element . data ( 'ui-sortable' ) ) {
182+ angular . forEach ( newVal , function ( value , key ) {
183+ if ( callbacks [ key ] ) {
184+ if ( key === 'stop' ) {
185+ // call apply after stop
186+ value = combineCallbacks (
187+ value , function ( ) { scope . $apply ( ) ; } ) ;
188+ }
189+ // wrap the callback
190+ value = combineCallbacks ( callbacks [ key ] , value ) ;
183191 }
184- // wrap the callback
185- value = combineCallbacks ( callbacks [ key ] , value ) ;
186- }
187- element . sortable ( 'option' , key , value ) ;
188- } ) ;
192+
193+ element . sortable ( 'option' , key , value ) ;
194+ } ) ;
195+ }
189196 } , true ) ;
190197
191198 angular . forEach ( callbacks , function ( value , key ) {
0 commit comments