@@ -47,6 +47,16 @@ angular.module('ui.sortable', [])
4747 return ( / l e f t | r i g h t / ) . test ( item . css ( 'float' ) ) || ( / i n l i n e | t a b l e - c e l l / ) . test ( item . css ( 'display' ) ) ;
4848 }
4949
50+ function getElementScope ( elementScopes , element ) {
51+ for ( var i = 0 ; i < elementScopes . length ; i ++ ) {
52+ var x = elementScopes [ i ] ;
53+ if ( x . element [ 0 ] === element [ 0 ] ) {
54+ return x . scope ;
55+ }
56+ }
57+ return null ;
58+ }
59+
5060 function afterStop ( e , ui ) {
5161 ui . item . sortable . _destroy ( ) ;
5262 }
@@ -126,7 +136,7 @@ angular.module('ui.sortable', [])
126136 } ;
127137 } ;
128138
129- callbacks . activate = function ( /* e, ui*/ ) {
139+ callbacks . activate = function ( e , ui ) {
130140 // We need to make a copy of the current element's contents so
131141 // we can restore it after sortable has messed it up.
132142 // This is inside activate (instead of start) in order to save
@@ -151,10 +161,20 @@ angular.module('ui.sortable', [])
151161 // exact match with the placeholder's class attribute to handle
152162 // the case that multiple connected sortables exist and
153163 // the placehoilder option equals the class of sortable items
154- var excludes = element . find ( '[class="' + phElement . attr ( 'class' ) + '"]' ) ;
164+ var excludes = element . find ( '[class="' + phElement . attr ( 'class' ) + '"]:not([ng-repeat], [data-ng-repeat]) ' ) ;
155165
156166 savedNodes = savedNodes . not ( excludes ) ;
157167 }
168+
169+ // save the directive's scope so that it is accessible from ui.item.sortable
170+ var connectedSortables = ui . item . sortable . _connectedSortables || [ ] ;
171+
172+ connectedSortables . push ( {
173+ element : element ,
174+ scope : scope
175+ } ) ;
176+
177+ ui . item . sortable . _connectedSortables = connectedSortables ;
158178 } ;
159179
160180 callbacks . update = function ( e , ui ) {
@@ -165,8 +185,9 @@ angular.module('ui.sortable', [])
165185 ui . item . sortable . dropindex = ui . item . index ( ) ;
166186 var droptarget = ui . item . parent ( ) ;
167187 ui . item . sortable . droptarget = droptarget ;
168- var attr = droptarget . attr ( 'ng-model' ) || droptarget . attr ( 'data-ng-model' ) ;
169- ui . item . sortable . droptargetModel = droptarget . scope ( ) . $eval ( attr ) ;
188+
189+ var droptargetScope = getElementScope ( ui . item . sortable . _connectedSortables , droptarget ) ;
190+ ui . item . sortable . droptargetModel = droptargetScope . ngModel ;
170191
171192 // Cancel the sort (let ng-repeat do the sort for us)
172193 // Don't cancel if this is the received list because it has
0 commit comments