components icon indicating copy to clipboard operation
components copied to clipboard

fix(material/list): selection list option selected value reset if form control is initialized to empty value

Open crisbeto opened this issue 5 years ago • 4 comments

Fixes the selected value of a mat-list-option that is set through an input being reset if a FormControl is assigned to the list with a default empty value.

crisbeto avatar Mar 28 '19 18:03 crisbeto

It looks like there's still an issue where the form control value is out of sync with the selected options after initialization

jelbourn avatar Mar 28 '19 23:03 jelbourn

To clarify, the individual options initialize before the @ContentChildren(MatListOption) options is initialized. The selected setter tells the list that it should update its value, but the _reportValueChange doesn't update the form model because those options are still undefined at that point.

We should probably add a subscription on the options query list that initializes the form state from the options if it hasn't been initialized already.

jelbourn avatar Mar 29 '19 00:03 jelbourn

@jelbourn isn't that what we're doing here in ngAfterContentInit?

crisbeto avatar Mar 31 '19 15:03 crisbeto

I mean that the SelectionModel does have the correct values from the selected property on the options.

jelbourn avatar Apr 01 '19 20:04 jelbourn

Closing since this is quite out of date and we haven't gotten any bug reports about it as far as I can see.

crisbeto avatar Feb 28 '24 08:02 crisbeto

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.