mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-21 07:10:59 +00:00
fix(ng:options): ng:change should be called after the new val is set
Closes #547
This commit is contained in:
parent
e54909f5ef
commit
06534413d3
2 changed files with 12 additions and 6 deletions
|
|
@ -762,8 +762,8 @@ angularWidget('select', function(element){
|
|||
}
|
||||
}
|
||||
if (isDefined(value) && model.get() !== value) {
|
||||
onChange(scope);
|
||||
model.set(value);
|
||||
onChange(scope);
|
||||
}
|
||||
scope.$root.$apply();
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -900,22 +900,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.$digest();
|
||||
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(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue