Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit e8931b9

Browse files
author
Brian Feister
committed
Merge pull request #501 from gotenxds/master
on-remove and on-select should fire AFTER addition/removal of the item
2 parents aa13ee3 + 517ec79 commit e8931b9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/select.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,11 @@
431431
ctrl.selected = item;
432432
}
433433

434-
ctrl.onSelectCallback($scope, {
434+
$timeout(function(){
435+
ctrl.onSelectCallback($scope, {
435436
$item: item,
436437
$model: ctrl.parserResult.modelMapper($scope, locals)
438+
});
437439
});
438440

439441
if (!ctrl.multiple || ctrl.closeOnSelect) {
@@ -495,9 +497,12 @@
495497
ctrl.activeMatchIndex = -1;
496498
ctrl.sizeSearchInput();
497499

498-
ctrl.onRemoveCallback($scope, {
499-
$item: removedChoice,
500-
$model: ctrl.parserResult.modelMapper($scope, locals)
500+
// Give some time for scope propagation.
501+
$timeout(function(){
502+
ctrl.onRemoveCallback($scope, {
503+
$item: removedChoice,
504+
$model: ctrl.parserResult.modelMapper($scope, locals)
505+
});
501506
});
502507
};
503508

test/select.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ describe('ui-select tests', function() {
774774
expect(scope.$model).toBeFalsy();
775775

776776
clickItem(el, 'Samantha');
777+
$timeout.flush();
778+
779+
777780
expect(scope.selection.selected).toBe('Samantha');
778781

779782
expect(scope.$item).toEqual(scope.people[5]);
@@ -858,6 +861,7 @@ describe('ui-select tests', function() {
858861
clickItem(el, 'Samantha');
859862
clickItem(el, 'Adrian');
860863
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
864+
$timeout.flush();
861865

862866
expect(scope.$item).toBe(scope.people[5]);
863867
expect(scope.$model).toBe('Samantha');
@@ -887,6 +891,7 @@ describe('ui-select tests', function() {
887891
clickItem(el, 'Samantha');
888892
clickItem(el, 'Adrian');
889893
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
894+
$timeout.flush();
890895

891896
expect(scope.$item).toBe(scope.people[5]);
892897
expect(scope.$model).toBe(scope.$item);

0 commit comments

Comments
 (0)