Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 99306dd

Browse files
committed
fix(sortable): fix tests failing with lazyInit
1 parent d8fa639 commit 99306dd

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/sortable.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ angular.module('ui.sortable', [])
230230
return;
231231
}
232232

233-
if (ngModel) {
234-
233+
function init () {
235234
// When we add or remove elements, we need the sortable to 'refresh'
236235
// so it can find the new/removed elements.
237236
scope.$watchCollection('ngModel', function() {
@@ -443,30 +442,31 @@ angular.module('ui.sortable', [])
443442
}, true);
444443

445444
patchUISortableOptions(opts);
446-
447-
} else {
448-
$log.info('ui.sortable: ngModel not provided!', element);
449445
}
450446

451447
var stopDisabledWatcher = angular.noop;
452448

453-
var startIfEnabled = function()
454-
{
455-
if(!scope.uiSortable.disabled)
456-
{
457-
// Create sortable
458-
element.sortable(opts);
459-
460-
// Stop Watcher
461-
stopDisabledWatcher();
449+
var startIfEnabled = function () {
450+
if (scope.uiSortable && scope.uiSortable.disabled) {
451+
return false;
452+
}
462453

463-
return true;
454+
if (ngModel) {
455+
init();
456+
} else {
457+
$log.info('ui.sortable: ngModel not provided!', element);
464458
}
465-
return false;
459+
460+
// Create sortable
461+
element.sortable(opts);
462+
463+
// Stop Watcher
464+
stopDisabledWatcher();
465+
466+
return true;
466467
};
467468

468-
if(!startIfEnabled())
469-
{
469+
if (!startIfEnabled()) {
470470
stopDisabledWatcher = scope.$watch('uiSortable.disabled', startIfEnabled);
471471
}
472472
}

0 commit comments

Comments
 (0)