diff --git a/src/select.js b/src/select.js index b4efeabca..44edd8e21 100644 --- a/src/select.js +++ b/src/select.js @@ -431,9 +431,11 @@ ctrl.selected = item; } - ctrl.onSelectCallback($scope, { + $timeout(function(){ + ctrl.onSelectCallback($scope, { $item: item, $model: ctrl.parserResult.modelMapper($scope, locals) + }); }); if (!ctrl.multiple || ctrl.closeOnSelect) { @@ -495,9 +497,12 @@ ctrl.activeMatchIndex = -1; ctrl.sizeSearchInput(); - ctrl.onRemoveCallback($scope, { - $item: removedChoice, - $model: ctrl.parserResult.modelMapper($scope, locals) + // Give some time for scope propagation. + $timeout(function(){ + ctrl.onRemoveCallback($scope, { + $item: removedChoice, + $model: ctrl.parserResult.modelMapper($scope, locals) + }); }); }; diff --git a/test/select.spec.js b/test/select.spec.js index 6aab1b491..70b4acd14 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -774,6 +774,9 @@ describe('ui-select tests', function() { expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(scope.selection.selected).toBe('Samantha'); expect(scope.$item).toEqual(scope.people[5]); @@ -858,6 +861,7 @@ describe('ui-select tests', function() { clickItem(el, 'Samantha'); clickItem(el, 'Adrian'); el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + $timeout.flush(); expect(scope.$item).toBe(scope.people[5]); expect(scope.$model).toBe('Samantha'); @@ -887,6 +891,7 @@ describe('ui-select tests', function() { clickItem(el, 'Samantha'); clickItem(el, 'Adrian'); el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + $timeout.flush(); expect(scope.$item).toBe(scope.people[5]); expect(scope.$model).toBe(scope.$item);