Skip to content

Commit bf69aa1

Browse files
committed
fix(ng:options): ng:change should be called after the new val is set
Closes angular#547 Conflicts: test/widgetsSpec.js
1 parent 15e3b2d commit bf69aa1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/widgets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ angularWidget('select', function(element){
765765
}
766766
}
767767
if (isDefined(value) && model.get() !== value) {
768-
onChange(scope);
769768
model.set(value);
769+
onChange(scope);
770770
}
771771
scope.$tryEval(function(){
772772
scope.$root.$eval();

test/widgetsSpec.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -882,22 +882,28 @@ describe("widget", function(){
882882
createSelect({
883883
name:'selected',
884884
'ng:options':'value for value in values',
885-
'ng:change':'count = count + 1'
885+
'ng:change':'log = log + selected.name'
886886
});
887887
scope.values = [{name:'A'}, {name:'B'}];
888888
scope.selected = scope.values[0];
889-
scope.count = 0;
889+
scope.log = '';
890890
scope.$eval();
891-
expect(scope.count).toEqual(0);
891+
expect(scope.log).toEqual('');
892892

893893
select.val('1');
894894
browserTrigger(select, 'change');
895-
expect(scope.count).toEqual(1);
895+
expect(scope.log).toEqual('B');
896896
expect(scope.selected).toEqual(scope.values[1]);
897897

898+
// ignore change event when the model doesn't change
898899
browserTrigger(select, 'change');
899-
expect(scope.count).toEqual(1);
900+
expect(scope.log).toEqual('B');
900901
expect(scope.selected).toEqual(scope.values[1]);
902+
903+
select.val('0');
904+
browserTrigger(select, 'change');
905+
expect(scope.log).toEqual('BA');
906+
expect(scope.selected).toEqual(scope.values[0]);
901907
});
902908

903909
it('should update model on change through expression', function(){

0 commit comments

Comments
 (0)