Skip to content

Commit

Permalink
fix(ng:options): ng:change should be called after the new val is set
Browse files Browse the repository at this point in the history
Closes angular#547

Conflicts:

	test/widgetsSpec.js
  • Loading branch information
groner committed Sep 5, 2011
1 parent 15e3b2d commit bf69aa1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ angularWidget('select', function(element){
}
}
if (isDefined(value) && model.get() !== value) {
onChange(scope);
model.set(value);
onChange(scope);
}
scope.$tryEval(function(){
scope.$root.$eval();
Expand Down
16 changes: 11 additions & 5 deletions test/widgetsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,22 +882,28 @@ describe("widget", function(){
createSelect({
name:'selected',
'ng:options':'value for value in values',
'ng:change':'count = count + 1'
'ng:change':'log = log + selected.name'
});
scope.values = [{name:'A'}, {name:'B'}];
scope.selected = scope.values[0];
scope.count = 0;
scope.log = '';
scope.$eval();
expect(scope.count).toEqual(0);
expect(scope.log).toEqual('');

select.val('1');
browserTrigger(select, 'change');
expect(scope.count).toEqual(1);
expect(scope.log).toEqual('B');
expect(scope.selected).toEqual(scope.values[1]);

// ignore change event when the model doesn't change
browserTrigger(select, 'change');
expect(scope.count).toEqual(1);
expect(scope.log).toEqual('B');
expect(scope.selected).toEqual(scope.values[1]);

select.val('0');
browserTrigger(select, 'change');
expect(scope.log).toEqual('BA');
expect(scope.selected).toEqual(scope.values[0]);
});

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

0 comments on commit bf69aa1

Please sign in to comment.