Skip to content

Commit

Permalink
fix(select): value set through property not being propagated to value…
Browse files Browse the repository at this point in the history
… accessor

Fixes values set through the `value` property not being propagated to the `value` in the `ControlValueAccessor`.

Fixes #10214.
  • Loading branch information
crisbeto committed Mar 2, 2018
1 parent 915a2b7 commit 8fcfbb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,19 @@ describe('MatSelect', () => {
expect(requiredMarker)
.not.toBeNull(`Expected label to have an asterisk, as control was required.`);
}));

it('should propagate the value set through the `value` property to the form field',
fakeAsync(() => {
const control = fixture.componentInstance.control;

expect(control.value).toBeFalsy();

fixture.componentInstance.select.value = 'pizza-1';
fixture.detectChanges();

expect(control.value).toBe('pizza-1');
}));

});

describe('disabled behavior', () => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
if (newValue !== this._value) {
this.writeValue(newValue);
this._value = newValue;
this._onChange(newValue);
}
}
private _value: any;
Expand Down

0 comments on commit 8fcfbb7

Please sign in to comment.