fix(material/chips): error if selected value is accessed too early#23419
fix(material/chips): error if selected value is accessed too early#23419zarend merged 1 commit intoangular:masterfrom
Conversation
src/material/chips/chip-list.ts
Outdated
| /** The array of selected chips inside chip list. */ | ||
| get selected(): MatChip[] | MatChip { | ||
| return this.multiple ? this._selectionModel.selected : this._selectionModel.selected[0]; | ||
| return this.multiple ? this._selectionModel?.selected : this._selectionModel?.selected[0]; |
There was a problem hiding this comment.
The MatChip[] | MatChip type here seems off, since this can return undefined. I don't think we can fix it without a breaking change, but in the multiple case we could at least return an empty array?
There was a problem hiding this comment.
Changed, although my thinking is that this is somewhat of an edge case. You'll have to try access selected before change detection has run in order for it to break (e.g. by doing it in the constructor). I submitted the fix since we had a similar issue report in mat-select.
Similar issue to angular#23378. The chip list will throw an error if the `selected` value is accessed before the selection model has been initialized.
fde293e to
d8467af
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Similar issue to #23378. The chip list will throw an error if the
selectedvalue is accessed before the selection model has been initialized.