This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
mdc-select does not select the option when set value through form control asynchronously #1638
Closed
Description
What Angular MDC version are you using?
0.42.2
What browser(s) is this bug affecting?
Tested on Chrome, Firefox
What OS are you using?
MacOS
What are the steps to reproduce the bug?
- Create template with
mdc-select
with*ngFor
options. - Asynchronously assign dynamic options.
- Set value of
FormControl
programmatically (viaFormControl::setValue
orFormGroup::patchValue
).
What is the expected behavior?
mdc-select
is selected on the option that has the newly assigned value.
What is the actual behavior?
mdc-select
is selected on the first option.
Some reproducible snippet
Template
<div [formGroup]="form">
<mdc-select formControlName="select">
<option *ngFor="let number of numbers" [value]="number">{{ number }}</option>
</mdc-select>
</div>
Controller
form = this.fb.group({
select: '',
});
numbers = ['1', '2', '3', '4', '5'];
ngOnInit() {
setTimeout(() => {
this.numbers = ['6', '7', '8'];
this.form.controls.select.setValue('7');
}, 100);
}