Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,16 @@ describe('MatSelect', () => {

expect(trigger.textContent).not.toContain('Pizza');
}));

it('should sync up the form control value with the component value', fakeAsync(() => {
const fixture = TestBed.createComponent(BasicSelectOnPushPreselected);
fixture.detectChanges();
flush();

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

});

describe('with custom trigger', () => {
Expand Down Expand Up @@ -4723,6 +4733,7 @@ class BasicSelectOnPush {
`
})
class BasicSelectOnPushPreselected {
@ViewChild(MatSelect) select: MatSelect;
foods: any[] = [
{ value: 'steak-0', viewValue: 'Steak' },
{ value: 'pizza-1', viewValue: 'Pizza' },
Expand Down
6 changes: 5 additions & 1 deletion src/material/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,11 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
// Defer setting the value in order to avoid the "Expression
// has changed after it was checked" errors from Angular.
Promise.resolve().then(() => {
this._setSelectionByValue(this.ngControl ? this.ngControl.value : this._value);
if (this.ngControl) {
this._value = this.ngControl.value;
}

this._setSelectionByValue(this._value);
this.stateChanges.next();
});
}
Expand Down